homepage Welcome to WebmasterWorld Guest from 54.166.148.189
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderator: open

CSS Forum

    
Applying an External Stylesheet
using JavaScript
joshie76




msg:1208943
 9:09 am on Apr 12, 2002 (gmt 0)

I only need this for IE5+ but basically we want to script the inclusion of an external stylesheet using javascript (to a child window).

We could use:
document.body.insertAdjacentHTML('beforeEnd','<link etc etc>');

but I'm sure there must be a more elegant solution.

 

tedster




msg:1208944
 3:42 am on Apr 13, 2002 (gmt 0)

Seems like that's the direction you need...not sure what else you can do, joshie76

joshie76




msg:1208945
 12:16 pm on Apr 13, 2002 (gmt 0)

Well darn it. My original idea (above) doesn't actually seem to work. Bit stuck now, any other ideas guys?

Let me quickly explain why we need it. The child window's (iframe) source is dynamically generated by a .dll (organisation chart software). This is a stand alone product which we are integrating into another web app and want to add some of our web app style to it. The chances of the .dll output changing to include our stylesheet are zero - hence our need for a client-side solution.

joshie76




msg:1208946
 4:19 pm on Apr 13, 2002 (gmt 0)

Got it!

<iframe name="myiframe" src="page.htm">
</iframe>

<script type="text/javascript">
window.myiframe.attachEvent('onload',attachCSS)
function attachCSS()
{
linkelm=document.createElement("link");
linkelm.rel="stylesheet";
linkelm.type="text/css";
linkelm.href="test.css";
window.myiframe.document.body.insertAdjacentElement('beforeEnd',linkelm);
}
</script>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved