Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.write bug 1

Status
Not open for further replies.

transparent

Programmer
Sep 15, 2001
333
GB
I have the following javascript:

<script lang="javascript">

function window::eek:nload()
{

if(window.self!=window.top)
{
document.write("<link media=\"screen\" href=\"css/slam_mythomson.css\" type=\"text/css\" rel=\"stylesheet\">");
}

}

</script>

This is embbedded within a page.

The function detects if it is within an IFRAME

This works well.

If it is within an Iframe, the following html is supposed to be outputed to the source:

<link media="screen" href="css/slam_mythomson.css" type="text/css" rel="stylesheet">

It does this!

But no other content on the page is outputed!!!

Whats going on???
 
This is not a bug - you are simply misunderstanding how document.write works.

If you use document.write AFTER the page has loaded, all other content is overwritten.

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Okay.

So how can I add the css to the page with javascript?
 
try
Code:
var head = document.getElementsByTagName("head")[0];
var css = document.createElement("link");
 css.setAttribute("media", "screen");
 css.setAttribute("href", "css/slam_mythomson.css");
 css.setAttribute("type", "text/css");
 css.setAttribute("rel", "stylesheet");
head.appendChild(css);

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top