我有一些代碼異步加載在我的網站上的廣告,看起來像這樣:異步的onload在這種情況下不工作
<div id="ad-div"></div>
<script>function onAdReady() {
debug_log('Method onAdReady called');
new Ad(document.getElementById("ad-div"))
}
</script>
<script src="http://content.xxxxx.com/ads/ads.min.js" async onload="onAdReady()"></script>
的問題是,onAdReady
功能永遠不會beeing調用。這樣做的原因可能是包含該段中的html代碼beeing通過JavaScript加載在首位是這樣的:是beeing在$(document).ready(function() {]
的情況下,可能重要執行
// Initiate out_window_view
$.ajax({
url: loadPagePath("main.html"),
success: function (result) {
debug_log("Going in main.html view");
$("#content").html(result);
},
error: function (result) {
debug_log("Error, failed to load out_window_main view");
}
});
此代碼。 任何人都可以向我展示爲什麼這不起作用,併爲我提供解決此問題的解決方法或替代方法?
謝謝,這是一個非常好的解釋。我想我現在可以修復它 –