View Full Version : Applying Stylesheet to IFRAME contents
m0nde
06-28-2005, 05:57 PM
I'm using vbadvanced and have created a module to show information in an IFRAME.
However, the contents of the IFRAME is never formatted according to what I've set up in my style. The contents always has a white background with black text in Times New Roman.
Is there something I'm missing?
I've tried to include a class="alt1" in the IFRAME tag and have even surrounded the contents of the HTML file in <span class="alt1"> tags, all to no avail.
Included is an example:
<td class="$getbgrow alt1" width="100%" align="center">
<iframe title="Text" name="I1" width="100%" height="100" src="/forums/modules/text.html" marginwidth="1" marginheight="1" scrolling="auto" border="0" frameborder="0">
<!-- Alternate content for non-supporting browsers -->
<a href="/forums/modules/text.html" target="_blank">Text</a>
</iframe></td>
The text.html file is a very long page and that is why I want it included in an IFRAME with a scroll bar.
<span class="alt1"><strong>Blah blah blah ...</strong><br /><br />Blah blah blah</span>
- Sid
tamarian
06-28-2005, 06:21 PM
I think the iframe page needs access to the style sheet on it's own, since it's loaded separately. That's just a guess :) To test this guess, save a copy of your stylesheet to a file, and add the file to the iframe page...
m0nde
06-29-2005, 12:26 AM
I think the iframe page needs access to the style sheet on it's own, since it's loaded separately.Sorry for being daft, but how do I do this? I understand that it needs access to the .CSS information but I have several themes on my vbulletin site, so how will I get this to work?
- Sid
tamarian
06-29-2005, 12:37 AM
Sorry for being daft, but how do I do this? I understand that it needs access to the .CSS information but I have several themes on my vbulletin site, so how will I get this to work?
- Sid
Ah, I didn't consider multiple styles. One possible solution is to make the iframe file a PHP file. This way you can include global.php which should give you access to the user's style.
deathemperor
06-29-2005, 02:24 AM
that iframe is simply a page, so you need to use $headinclude to get the CSS properly.
m0nde
06-29-2005, 08:55 PM
that iframe is simply a page, so you need to use $headinclude to get the CSS properly.I have no idea how to use $headinclude :( Please spell it out for me.
One possible solution is to make the iframe file a PHP file. This way you can include global.php which should give you access to the user's style.I did the following and named it text.php and it just got me a blank IFRAME :ermm: :
<?php
require_once('/forums/global.php');
?>
<span class="alt1"><strong>Blah...etc.</strong><br /><br />More blah</span>Can you tell me what I should do to remedy this?
- Sid
I'm trying to do the same thing. Solved the problem by putting $style[css] in the <head> tags.
m0nde
06-30-2005, 12:22 PM
I'm trying to do the same thing. Solved the problem by putting $style[css] in the <head> tags.When I put $style[css] in the <head> tags of the IFRAME'D html file, I get the words $style[css] showing up as text in the IFRAME.
tamarian
06-30-2005, 12:42 PM
Put it this way:
<? echo $style['css']; ?>
m0nde
06-30-2005, 01:56 PM
Put it this way:
<? echo $style['css']; ?>Thankyou for spelling this out. I'm a total PHP newbie as you can tell! :speechless:
Now, I've done what you've said and this is the code I've got:
<html>
<head>
<? echo $style['css']; ?>
</head>
<body>
<span class="alt1"><strong>Blah...</strong><br /><br />Blah Blah</span>
</body>
</html>I've named this text.html and I'm calling this using an IFRAME.
But when I do this, I just get a white background with black text and no formatting other than the bold and line breaks in the scrolling IFRAME.
Can someone tell me what I'm doing wrong?
- Sid
tamarian
06-30-2005, 02:51 PM
<html>
<head>
<? echo $style['css']; ?>
</head>
<body>
<span class="alt1"><strong>Blah...</strong><br /><br />Blah Blah</span>
</body>
</html>
You're missing global.php. Try this:
<? require_once('global.php'); ?>
<html>
<head>
<? echo $style['css']; ?>
</head>
<body>
<span class="alt1"><strong>Blah...</strong><br /><br />Blah Blah</span>
</body>
</html>
Which may produce some warning, but let's see if it works.
m0nde
06-30-2005, 03:20 PM
Actually, no warning occurs and no changes either :(
It still shows a white background with black text.
- Sid
tamarian
06-30-2005, 03:34 PM
We may have missed something very simple. alt1 and alt2 do not apply to <span>, I don't think.
You can test by accessing ther iframe page directly from the browser, and view the source, to see if the style is there as expected.
m0nde
06-30-2005, 03:54 PM
We may have missed something very simple. alt1 and alt2 do not apply to <span>, I don't think.
You can test by accessing ther iframe page directly from the browser, and view the source, to see if the style is there as expected.If I access this page directly it still shows up as black Times New Roman (browser default font) text with a white background.
Even if the alt1 and alt2 aren't working properly, shouldn't the colour work? ...and the font?
I know that people have used IFRAMEs to display things like the shoutbox, etc.
- Sid
tamarian
06-30-2005, 03:59 PM
I'm not sure because I don't have the files.
But what happens when you view the page source? What style is defined there?
m0nde
06-30-2005, 04:07 PM
The source, when viewing the file directly in a web browser doesn't expand the PHP script at all!
It just shows the literal text. Why is this?
- Sid
tamarian
06-30-2005, 04:43 PM
The source, when viewing the file directly in a web browser doesn't expand the PHP script at all!
It just shows the literal text. Why is this?
- Sid
That's how it should work. You're all set.
m0nde
06-30-2005, 11:53 PM
That's how it should work. You're all set.You're telling me the source, when viewed in a web browser is supposed to show up like:
<? require_once('/forums/global.php'); ?>
<html>
<head>
<? echo $style['css']; ?>
</head>
<body>
<span class="alt1"><strong>Blah</strong><br /><br />Blah Blah</span>
</body>
</html>I thought that the require_once was supposed to actually include all of global.php in that space and that the command to echo the style variable was supposed to type out the contents of that variable in that space.
tamarian
06-30-2005, 11:58 PM
No, I thought you said it showed the lirterals. I took that to mean the actual colour codes for alt1 and alt2.
The page view you showed tells me that you have not made the file a .php as I suggested earlier. To interpret it as PHP, it needs to be a PHP extension. :)
m0nde
07-01-2005, 12:35 AM
To interpret it as PHP, it needs to be a PHP extension. :)Thanks. I have tried this both with an HTML extension and a PHP extension. When I try it with a PHP extension, it just shows up as blank with a white background. You've seen above what happens when I try it with an HTML extension.
The source of the PHP file if viewed after being parsed shows up as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>It seems that the global.php is the problem because if that is excluded the rest of the file shows something. I know that global.php resides in that place (/forums/global.php) and I've tried replacing the whole thing with:
<? phpinfo(); ?> to test whether anything's going on and this does show the information page in the IFRAME.
- Sid
deathemperor
07-01-2005, 02:15 AM
the page must be save as .php page, .html page won't work.
m0nde
07-01-2005, 02:33 AM
the page must be save as .php page, .html page won't work.I have saved the page as a .php page. The file being called for the IFRAME is text.php and has the following inside it:
<? require_once('/forums/global.php'); ?>
<html>
<head>
<? echo $style['css']; ?>
</head>
<body>
<span class="alt1"><strong>Blah</strong><br /><br />Blah Blah</span>
</body>
</html>When I view this text.php in the browser, not trying to view it in the IFRAME, to test it, I get a blank page. I then view the source and get:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>If I just put
<? phpinfo(); ?>into my text.php file, to see if anything works at all, I see the php information whether I view it in my IFRAME or if I just view it normally. What is happening with the call to the global.php? Am I doing this wrong?
- Sid
tamarian
07-01-2005, 02:54 AM
Sid, this may be a problem of not including global.php You are including it, but the path may be wrong, as it will depend on where your test.php file exist. Try running it in your main forum home first, and remove that '/forum/' directory from the path.
m0nde
07-01-2005, 03:06 AM
Sid, this may be a problem of not including global.php You are including it, but the path may be wrong, as it will depend on where your test.php file exist. Try running it in your main forum home first, and remove that '/forum/' directory from the path.Yes, this is what I think is happening. I do know that global.php exists in my /forums directory because if I try http://www.bostonlove.org/forums/global.php it comes up and says
Critical Error
global.php must not be called directly.This is very odd. I will try to run it in the same directory as global.php without any path in that line and see what happens.
- Sid
If I move it into the same folder as global.php it suddenly works!
I think I'll just leave it there! Thank you very much for your help.
But, for future reference, can you explain to me why this is happening?
Should I change that line to a relative path?
[php]<? require_once('../global.php'); ?>- Sid
deathemperor
07-01-2005, 08:52 AM
Should I change that line to a relative path?
both work fine if you use the correct path
m0nde
07-02-2005, 08:52 PM
both work fine if you use the correct pathThis is inside a module on my vBadvanced CMPS front page. Do you think that this is somehow changing the path?
- Sid
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.