2012-08-14 17 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