TwoD
07-14-04, 05:36 AM
I noticed that if you use javascript to print a stylesheet tag onto your page in any other way than with document.write() it won't be added to the page. Atleast not in IE6 which is what I've tested it in.
Here's an example:
<html>
<body>
<script>
document.write("<style>.Test{color:blue}</style>") // Will work
//document.body.innerHTML += "<style>.Test{color:blue}</style>" //Won't work
//document.body.innerHTML += "a<style>.Test{color:blue}</style>" //Will work
//document.body.insertAdjacentHTML("beforeEnd","<style>.Test{color:blue}</style>") // Won't work
//document.body.insertAdjacentHTML("beforeEnd","a<style>.Test{color:blue}</style>") //Will work
</script>
<div class="Test">Test</div>
</body>
</html>
Just remove/add the comments to see what I mean.
It doesn't have to be an a before the tag, any character(s) will do.
Does anyone know why this happens?
Here's an example:
<html>
<body>
<script>
document.write("<style>.Test{color:blue}</style>") // Will work
//document.body.innerHTML += "<style>.Test{color:blue}</style>" //Won't work
//document.body.innerHTML += "a<style>.Test{color:blue}</style>" //Will work
//document.body.insertAdjacentHTML("beforeEnd","<style>.Test{color:blue}</style>") // Won't work
//document.body.insertAdjacentHTML("beforeEnd","a<style>.Test{color:blue}</style>") //Will work
</script>
<div class="Test">Test</div>
</body>
</html>
Just remove/add the comments to see what I mean.
It doesn't have to be an a before the tag, any character(s) will do.
Does anyone know why this happens?