Lleoun
04-15-2009, 09:02 AM
Hi all,
From a js file I want to add the following to the head tag:
<style type="text/css">
@import "http://www.myweb.com/css/style.css";
</style>
I'm using the code below, and it works perfect for Firefox and the rest, but it crashes Internet Explorer.
Can someone please give me a hand with it??
Thanks a ton in advance!
function newScript4(){
var js4=document.createElement('style');
js4.setAttribute("type","text/css");
var thetext = "@import 'http://www.myweb.com/css/style.css';";
if (js4.styleSheet) { // IE
js4.styleSheet.cssText = thetext; // this line crashes IE
js4.styleSheet.addImport('http://www.myweb.com/css/style.css'); //this other line cashes IE too
} else { // the world
var tx = document.createTextNode(thetext);
js4.appendChild(tx);
}
document.getElementsByTagName('head')[0].appendChild(js4)
}
newScript4();
From a js file I want to add the following to the head tag:
<style type="text/css">
@import "http://www.myweb.com/css/style.css";
</style>
I'm using the code below, and it works perfect for Firefox and the rest, but it crashes Internet Explorer.
Can someone please give me a hand with it??
Thanks a ton in advance!
function newScript4(){
var js4=document.createElement('style');
js4.setAttribute("type","text/css");
var thetext = "@import 'http://www.myweb.com/css/style.css';";
if (js4.styleSheet) { // IE
js4.styleSheet.cssText = thetext; // this line crashes IE
js4.styleSheet.addImport('http://www.myweb.com/css/style.css'); //this other line cashes IE too
} else { // the world
var tx = document.createTextNode(thetext);
js4.appendChild(tx);
}
document.getElementsByTagName('head')[0].appendChild(js4)
}
newScript4();