...

View Full Version : Javascript code not working in IE



brien
10-04-2008, 08:10 PM
can someone help me with why this won't work in IE?


<script type="text/javascript">
var d = document;
function set_random_background(where) {
var backgrounds = [
["back1.png", "#000000"],
["back2.png", "#000000"],
];
var index = Math.floor(Math.random() * backgrounds.length);
var style_element = d.createElement("style");
style_element.setAttribute("type", "text/css");
style_element.setAttribute("media", "all");
d.getElementsByTagName("body").item(0).appendChild(style_element);
style_element.sheet.insertRule("#"+where+" { background: " + backgrounds[index][1] + " url(\"" + backgrounds[index][0] + "\") center top no-repeat scroll; }", 0);
}
(function verify_URI() {
var ignore = false;
var directory_blacklist = [
"profile\/username\/",
"profiles\/",
"xn\/"
];
for (var i = 0; i < directory_blacklist.length; i++) {
if (new RegExp("^http:\/\/www\.example\.org\/" + directory_blacklist[i]).test(d.URL)) {
ignore = true;
}
}
if (ignore === false) {
set_random_background('somedivid');
}
})();
</script>

Thanks!

abduraooft
10-05-2008, 02:00 PM
IE won't allow document.createElement('style') (http://www.quirksmode.org/bugreports/archives/2006/01/IE_wont_allow_documentcreateElementstyle.html)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum