1

This code is not working on IE8 at all. FF3 is executing but the page is blank and seems loading not ending.

My code is:

$("#leaderBoard").html("<script2 language=\"javascript2\"> document.write('<scr'+'ipt language=\"javascript21.1\">alert(1)</scri'+'pt>'); </script2>".replace(/script2/gi, "script"));

I want to let page load ad on ready.

2
  • are you trying to load a script when dom is ready? Commented Dec 3, 2008 at 10:48
  • Use of the language attribute is depricated. Use type="text/javascript" instead. Also, prefer DOM over document.write. Also... use jQuery's script loader, or eval. Commented Dec 3, 2008 at 11:07

6 Answers 6

5

This works for me in FF3 and IE7:

$("#leaderBoard").html('<sc'+'ript language="javascript1.1">alert(1);</sc'+'ript>');

When you use document.write after the page has loaded, it replaces the entire document (http://javascript.about.com/library/blwrite.htm). You essentially replaced your page content with a script tag, causing it to appear blank.

Sign up to request clarification or add additional context in comments.

Comments

3

When you actually have jQuery already, why all the obfuscating hassle?

Simply load the ad HTML into the leaderBoard object, and you're done.

$(document).ready( function() {
  $("#leaderBoard").load("/ad_generator.php");
});

Where ad_generator.php would produce an HTML fragment based on some randomization scheme.

Comments

1

Why not try using jQuery's $.getScript(); function?

http://docs.jquery.com/Ajax/jQuery.getScript

Comments

1

Try this approach:

//////////////////function in page's script section

function aFunction (x) {

    ////script you want to execute

    alert(x);

}

//////////////////////in page's body

var d = $("<div />");
d.ready(function(){aFunction("x");});

Comments

0

try wrapping your code in

$(document).ready(function() {
 // your code here
});

Comments

0
document.write()

does not work with the window.onload event

try this code

 $('.myDiv').html('<script src="path\/to-add\/provider"><\/script>');

somewhere near the end of your document Notice that you have to escape the '/' charecter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.