2012-08-14 58 views
0

我想在页面加载后执行广告脚本。 我知道我不得不使用这样的事情:如何使用jquery执行外部脚本

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

,但它不工作,虽然警报负载。也没有问题

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

问题必须从$ .getScript。 我还必须补充的是,外部脚本输出是这样的:

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

“);

回答

0

只需使用

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

如果用脚本,而不是装载功能有问题,请继续阅读。

$.getScript是ajax调用的快捷方式。您可以在http://api.jquery.com/jQuery.getScript/的文档中找到更多信息。由于same origin policy无法加载脚本。您必须使用JSONP才能从其他域加载脚本。你可以在这个post找到更多的细节。

+0

但我的问题是$ .getScript,加载事件正在工作。 – kami 2012-08-14 20:48:35