Forum Moderators: open

Message Too Old, No Replies

Link to stylesheet when page finishes loading

         

spirelli

2:28 pm on Jan 28, 2008 (gmt 0)

10+ Year Member



I want to preload some images that are included as backgrounds in an external css file. In order to have all page content loaded and displayed before additional images are preloaded I thought I link to the stylesheet only once the page has loaded. Maybe you can see what I've tried to do: However, it breaks the page somehow. Resulting the page to become blank after loading.

In the header is:

<script type="text/javascript">
function preloadimgs ()
{
document.write('<link href="css/preload_aboutus.css" rel="stylesheet" type="text/css" ></style>');
}
</script>

And then:

<body id="general" onload="preloadimgs()">

What's wrong with my approach?

mehh

6:41 pm on Jan 28, 2008 (gmt 0)

10+ Year Member



after the page has finnished loading, document.write() overwrites the page rather than adding to it use something like this instead:
function preloadimgs (){
var l=document.createElement("link");
l.rel="stylesheet";
l.type="text/css";
l.href="css/preload_aboutus.css";
document.getElementByTagName("head")[0].appendChild(l);
}