views:

2694

answers:

6

Hi all, my Code is like

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

ie8 not wirking at all. FF3 is exucuting but page gets blank and seems loading not ending.

someone has a clue?

i want to let page load ad on ready.

A: 

try wrapping your code in

$(document).ready(function() {
 // your code here
});
adam
+3  A: 

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.

Tomalak
+2  A: 

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.

+1  A: 

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

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

sanchothefat
A: 
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

Mihai Lazar
A: 

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 = $(""); d.ready(function(){aFunction("x");});