Google Answers Logo
View Question
 
Q: CSS and IFRAME ( No Answer,   5 Comments )
Question  
Subject: CSS and IFRAME
Category: Computers > Internet
Asked by: petef-ga
List Price: $15.00
Posted: 20 May 2002 18:41 PDT
Expires: 27 May 2002 18:41 PDT
Question ID: 17178
How can I apply a css stylesheet to the contents of an iframe
*without* direct access to the inlined document?
Answer  
There is no answer at this time.

The following answer was rejected by the asker (they reposted the question).
Subject: Re: CSS and IFRAME
Answered By: skermit-ga on 20 May 2002 18:55 PDT
 
If you have PHP on your webserver, you can write a PHP wrapper to put
a CSS tag into the new temp-html document that you iframe. Let's say
you're iframing &lt;a href=&quot;<a href="http://www.tinkywink.com/index.html">http://www.tinkywink.com/index.html</a>&quot;&gt;<a href="http://www.tinkywink.com/index.html">http://www.tinkywink.com/index.html</a>&lt;/a&gt; . Instead, point
the iframe to tinkywink.php and in this file:
 
tinkywink.php: 
&amp;lt;HTML&amp;gt; 
&amp;lt;HEAD&amp;gt; 
&amp;lt;LINK REL=StyleSheet HREF=&amp;quot;example_style.css&amp;quot; TYPE=&amp;quot;text/css&amp;quot;&amp;gt; 
&amp;lt;?php 
include(&amp;quot;&lt;a href=&quot;<a href="http://tinkywink.com/index.html">http://tinkywink.com/index.html</a>&quot;&gt;<a href="http://tinkywink.com/index.html">http://tinkywink.com/index.html</a>&lt;/a&gt;&amp;quot;); 
?&amp;gt; 
&amp;lt;/HTML&amp;gt; 
 
It's that simple. Good luck!  

Request for Answer Clarification by petef-ga on 22 May 2002 17:56 PDT
&amp;gt; It's that simple. Good luck!  
 
Well it's a neat idea but... it's a non-standards compliant fudge.   
Doing what you suggest will generate an embedded page that looks like:
 
  &amp;lt;HTML&amp;gt;  
  &amp;lt;HEAD&amp;gt;  
  &amp;lt;LINK REL=StyleSheet HREF=&amp;quot;example_style.css&amp;quot; TYPE=&amp;quot;text/css&amp;quot;&amp;gt;  
    &amp;lt;html&amp;gt; 
      &amp;lt;head&amp;gt;...&amp;lt;/head&amp;gt; 
      &amp;lt;body&amp;gt;...&amp;lt;/body&amp;gt; 
    &amp;lt;/html&amp;gt; 
  &amp;lt;/HTML&amp;gt;  
 
who knows how that is going to render (even with a closing head tag)? 
   
When I tried it with jsps on tomcat it doesn't work for a directory
listing, which is what I'm after.  If I do:
 
  &amp;lt;iframe src=&amp;quot;../files/&amp;quot;&amp;gt;...&amp;lt;/iframe&amp;gt; 
 
I get an embedded directory listing, which is what I want (although
not styled as I would like).  But if I do:
 
  &amp;lt;iframe src=&amp;quot;files.jsp&amp;quot;&amp;gt;...&amp;lt;/iframe&amp;gt; 
 
and have 
 
  &amp;lt;!-- files.jsp --&amp;gt; 
  &amp;lt;jsp:root xmlns:jsp=&amp;quot;&lt;a href=&quot;<a href="http://java.sun.com/JSP/Page">http://java.sun.com/JSP/Page</a>&quot;&gt;<a href="http://java.sun.com/JSP/Page">http://java.sun.com/JSP/Page</a>&lt;/a&gt;&amp;quot; version=&amp;quot;1.2&amp;quot;&amp;gt; 
    &amp;lt;jsp:include page=&amp;quot;../files&amp;quot; flush=&amp;quot;true&amp;quot;/&amp;gt; 
  &amp;lt;/jsp:root&amp;gt; 
   
I get a blank iframe.  Although it does work with an actual page
rather than a directory listing.
 
What I'm really after is something that is standards compliant and
doesn't rely on server side scripting.  If it *has* to rely on server
side scripting it *must* work with a directory listing.  

Clarification of Answer by skermit-ga on 23 May 2002 11:56 PDT
I'm sorry petef, my background on web programming is limited to basic
php scripting. I apologize for not being able to answer your clarified
question. Perhaps a commenter can help?  
Reason this answer was rejected by petef-ga:
The answerer gallantly admitted defeat in response to my request for
clarification (q.v.)

The following answer was rejected by the asker (they received a refund for the question).
Subject: Re: CSS and IFRAME
Answered By: samrolken-ga on 24 May 2002 21:58 PDT
 
I have searched, and there isn't a way to do this on the client side.
skermit had a good idea going about doing it server side, but not
enough there to implement it well.
 
I'm assuming that you're using a unix-type server environment. In that
case, I would put a shell script in the cgi-bin directory that does
these things:
 
First, use lynx to fetch the file you're going for. use the --source
arguement to make lynx just spit out the file to standard output. That
way, you'll get the source of whatever you need, even if it's a
directory listing.
 
Then, on that output, you'd want to insert the stylesheet right into
the document. The easiest way to do this would be to use sed. This
below is what you're going for:
 
lynx --source http://whatever/ | sed 's/&amp;lt;head&amp;gt;/&amp;lt;head&amp;gt;&amp;lt;link
rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text\/css&amp;quot; href=&amp;quot;stylesheet-url-here&amp;quot;&amp;gt;/i'
 
 
The idea of using the sed to insert the stylesheed link came from
Spatula.
[ &lt;a href=&quot;<a href="http://www.spatula.net/">http://www.spatula.net/</a>&quot;&gt;<a href="http://www.spatula.net/">http://www.spatula.net/</a>&lt;/a&gt; ] 
 
-- 
Sam Kennedy  

Request for Answer Clarification by petef-ga on 29 May 2002 08:49 PDT
&amp;gt; I have searched, and there isn't a way to do this on the client
side.
 
Hmmm.  :-( 
 
&amp;gt; I'm assuming that you're using a unix-type server environment.  
 
Well no actually, unfortunately. 
 
&amp;gt; In that case, I would put a shell script in the cgi-bin directory
...
&amp;gt; lynx --source http://whatever/ | sed 's/&amp;lt;head&amp;gt;/&amp;lt;head&amp;gt;&amp;lt;link 
&amp;gt;   rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text\/css&amp;quot; href=&amp;quot;stylesheet-url-here&amp;quot;&amp;gt;/i' 
 
Seems like a reasonable idea. 
 
I have now actually overridden the render() method in DefaultServlet
in Tomcat to output cleaner html, with a stylesheet link.  It works
but it's not the solution I wanted.  It seems to me that there *ought*
to be a way to style included documents without resorting to rewriting
them.
 
Thanks for trying peeps. 
-- 
petef  
Reason this answer was rejected by petef-ga:
Another reasonable idea but it didn't quite hit the spot.
--
petef

Comments  
Subject: Re: CSS and IFRAME
From: dgl-ga on 21 May 2002 08:14 PDT
 
Although the question doesn't say it, if that was an external site,
then it you are trusting that external site with the ability to
execute any php on your system  which generally isn't a good idea.

I think if it is an external site then because of cross site
javascript you can't use javascript to edit details of the iframe, but
if it was a page on the same domain then it would be possible to apply
a stylesheet via javascript.
Subject: Re: CSS and IFRAME
From: petef-ga on 22 May 2002 17:57 PDT
 
> Although the question doesn't say it, if that was an external site,
> then it you are trusting that external site with the ability to
> execute any php on your system  which generally isn't a good idea.

No you're not.  The php is a local wrapper for the remote file.
Subject: Re: CSS and IFRAME
From: dgl-ga on 25 May 2002 00:59 PDT
 
No.
In this case it's not a problem anyway, but using include() is a
mistake a lot of people make, because include allows a url they
presume it can be used to include pages. But the use for include is to
"includes and evaluates the specified file. "
(http://www.php.net/manual/en/function.include.php), so in that case
it is a risk.
Subject: Re: CSS and IFRAME
From: crosenblum-ga on 14 Jun 2002 14:29 PDT
 
Can't you just modify the contents of the iframe?

I have done that tons of times, to have an on the fly rotating banner..

It was very sweet...
Subject: Re: CSS and IFRAME
From: zeroasterisk-ga on 23 Jul 2004 13:26 PDT
 
I concur - simply use JS on the parent page to edit/update the
contents of the IFRAME with a link to a different stylesheet, or an
inline style block.

<html>
<body>
<script type="text/javascript">
function appendiframe(theIFRAME,theAPPEND)
	{	
		parent.frames[theIFRAME].document.body.innerHTML+=(theAPPEND);
	}
</script>

<DIV onclick="appendiframe('test','<STYLE>h1{color:red;}</STYLE><br><br>appended
content')" style="font-weight:bold;background-color:#bbbbbb;color:black;">
Test 1
</DIV>

<iframe name="test" ID="test" src="html1.html" frameborder="1"
style="width:90%;" align="center">this is not it.</iframe>
</body>
</html>



html1.html can be any page with h1 tags, to see the change made.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy