Dynamic iframe in php - php

I'm trying to set up a development server used by designers to test CSS before a deployment. The caveat is I want to be able to load HTML / PHP into an iframe, but have a variable passed to it that will allow me to swap the link to CSS from within the iframe. This will emulate the control I have over the production ad feeds that come via iframes.
I attempted a function that returned HTML with a variable css link, but it will not come back as an iframe, of course. The iframe will ensure the included css is the only css that will be used, and that the main page css will not affect the content of the iframe.
How can I load an iframe with a variable CSS link?

The solution is to use an iframe with a query string parameter on the source.
<iframe height="100%" width="100%" frameborder="0" src="/inc/mockads.php?css=<?=($settings['stylesheet']);?>">
which will pass the pre-defined stylesheet to the markup to be iframed. Then, in the mockads.php file, I add the logic to do:
<?php
if ( isset($_GET['css']) && strlen($_GET['css']) )
{
$stylesheet = $_GET['css'];
}
?>
Then the rest of the markup, with the link set like
<link rel="stylesheet" href="<?=$stylesheet;?>" type="text/css" media="all">

Related

How to check if my html will print longer than one page?

I was wondering if there was a way using php or javascript to see if my webpage will be longer than one page when printed. I have specific elements that need to be at the bottom of the page regardless of how long the content in the middle of the page is, (max one page including footer).
Tried various css elements such as bottom.
Have you tried making a separate 'print.css' file that only alters the way a page looks when it is going to be printed? <link rel="stylesheet" type="text/css" href="print.css" media="print">. This can also be done with an #media print { } tag in your regular css file.

browser ignores css printed by php

I have a stylesheet link that looks like below:
<link rel="stylesheet" href="/example/get_page.php?location=bla.css" id="main_ss" />
get_page.php just gets a URL using file_get_contents():
if (isset($_GET['location'])) {
echo file_get_contents('/example/styles/' . $_GET['location']);
}
I can see that the stylesheet file is being fetched properly (for example the text of the file is showing in firebug when I expend the link tag) but for some reason it is ignored by the browser. If I just fetch the CSS file directly of course everything works.
The code can be seen here: www.specman-verification.com/example/bla.html
Any leads? I'm at loss here.
Add the Content-type header like this (do this before you output anything):
header("Content-type: text/css");
Your code is just trying to load the script get_page.php. To load the CSS file you need:
<link rel="stylesheet" type="text/css" href="/example/bla.css" />
(or similar depending on the actual path to your CSS file). In other words the href attribute needs to specify the path to your spreadsheet file, not the HTML page file.
You need to do it the right way. I understand what you're doing here. You need a good mechanism to dynamically load external CSS and have the result display normal html in the browser output.
Follow the instructions on this url: http://www.warpconduit.net/2009/05/12/dynamically-load-css-and-js-files-using-php/
This will at least get you to have a mechanism to load external css file with php dynamically. You're definitely missing steps in your code.

Wordpress functions are not working inside iframe in wordpress

I am using an iframe in wordpress, but the page inside iframe not supporting wordpress functions.
the page inside iframe is from the same domain.
Here is what i am trying to do:
I am trying to call a css inside iframe page via wordpress function. Below is how i am using iframe tag :
<iframe id="iframeBox" src="<?php echo get_template_directory_uri();?>/iframe/scoreboard_summary.php" sandbox="" FRAMEBORDER="no" ></iframe>
Here is the css calling tag in my page scoreboard_summary.php :
<link type="text/css" rel="stylesheet" href="<?php echo get_template_directory_uri();?>/style.css">
the function get_template_directory_uri() is not working ?
Please let me know what should i need to do?
Thanks in advance.
iframes are just webpages pulled in and shown in a div. You can't interact with them in that way. PHP has already spit out what was defined by the loops and rules you set. You would want to look into ajax for something like that if you want to talk to the server and bring up new data at an interval, and skip the iframe.
<?php echo 'do this thing' ?> just turns into this thing after the page is loaded. There isn't much to hook into.
If you are just trying to get the stylesheet and apply it to you your page, then I would suggest getting the whole, standard, URL for that stylesheet and skip the template directory uri etc.
Maybe you can explain it better with some code or an example like this one, it's an iframe that refreshes at an interval. Good Luck!
http://jsfiddle.net/sheriffderek/3C9qP/

Change css class with php multi pages

I have a multiple pages website where I wan't to change some css stuffs.
So my index.php?p=page points to various pages but on every page I also want to adjust some css like the color of the currently active menu item(li) etc.
What is the best way to achieve this? Should i just make a php var on each page?
One way to handle this is to put a class on the BODY tag for each page, then make different subclasses for the stuff that changes. This way you don't need to feed in any variables from PHP. It's all done via CSS.
<body class="pageOne">
CSS:
.pageOne h1 {
color:#ff0000
}
.pageTwo h1 {
color:#000000
}
You should have the CSS on an external file, and link it using a <link> tag, like so:
<link rel="stylesheet" type="text/css" href="path_to_stylesheet.css">

PHP using a to css style a php file

is there a way to style a php file with css so I can use border,padding, align and teother various
will this work or not if i added to the php or will i need functions for using this
<link rel="stylesheet" type="text/css" href="style.css" />
You cannot and probably will never be able to style a PHP file using css. What you want to style using css is the html content created using PHP and/or javascript! That is because styling takes place on the client machine in order to show things to the user while php gets executed on the server machine in orderf to produce code which will be readable by a browser.
<link rel="stylesheet" type="text/css" href="style.css" /> will work if the file style.css is found at that location (i assume your are using valid css definitions in your file)
You can use css to style HTML files. PHP generates HTML (or not) and you cannot style PHP files.
PHP doesn't know or care about CSS, and neither does it need to.
PHP runs on the server and does whatever it does, which should result in an HTML document.
This HTML document is send to the browser.
Only the browser cares about CSS, and it doesn't care whether an HTML document was just a file on the server's hard disk or whether it was created by PHP or magic fairies.
If the document the browser receives is an HTML document, you can use CSS with it. PHP has absolutely zero influence on this.
You don't style PHP with CSS. What's there to style? It's all just server-side code that generates HTML. You style HTML with CSS, not PHP.
If you are looking for a way to define styles in variables i.e. colour etc and make it easier to generate css try http://lesscss.org/
It's what I use to make css edits faster instead of copying and pasting.

Categories