我有一些代码异步加载在我的网站上的广告,看起来像这样:异步的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");
}
});
此代码。 任何人都可以向我展示为什么这不起作用,并为我提供解决此问题的解决方法或替代方法?
谢谢,这是一个非常好的解释。我想我现在可以修复它 –