0

i want to execute an advertisement script after the page has been loaded. i know that i have to use something like this:

$(window).bind("load", function() {
$.getScript('http://anetwork.ir/showad/?adwidth=468&adheight=60&aduser=1341223032', function() {
    // callback function
    alert('external script loaded!');
  });
});

but it's not working, although the alert loads. also there is no problem with

$(window).bind("load", function()

the problem must be from $.getScript . i also must add that the external script outputs something like this:

document.write('<iframe scrolling="no" width="468" height="60" frameborder="0" src="http://anetwork.ir/showad/c.php?adwidth=468&adheight=60&aduser=1341223032">

');

kami
  • 1
  • 2
  • 3

1 Answers1

0

Simply use

$(window).load(function() {
   // this will be executed when the page has finished loading
}

If there is a problem with the script and not the load function, keep reading.

$.getScript is a shortcut for an ajax call. You can find more on that in the documentation on http://api.jquery.com/jQuery.getScript/. Because of the same origin policy it is not possible to load the script. You will have to use JSONP in order to load the script from a different domain. You can find more details on this in this post.

Community
  • 1
  • 1
dominik
  • 5,745
  • 6
  • 34
  • 45