有时我的广告导致我的网站陷入非常缓慢且内容未显示。我尝试过在内容之后加载顶部广告,但它不起作用;
<code><div id=”top_ad_loader” style=”display:none;”>adcode</div><script type=”text/javascript”>document.getElementById(“top_ad”).innerHTML =document.getElementById(“top_ad_loader”).innerHTML</script>
任何想法? 非常感谢
答案 0 :(得分:2)
只需在iframe中加载广告即可。它们不会减慢页面加载速度。
答案 1 :(得分:0)
加载页面后加载第三方广告并非易事。因为大多数广告使用document.write()
来添加其内容。加载网站后使用document.write会导致整个页面变为空白。
要做的一件事就是在页面顶部覆盖document.write并自己操作内容。
示例:
// top of the page
var adContent = [];
document.write = function (a){
adContent.push(a);
}
现在,您的所有广告数据都在adContent
数组中,您可以检查内容并将其附加到写入部分。
答案 2 :(得分:0)
您尝试的技术 - 脚本标记上的innerHTML - 只是不起作用。
相反,您需要在页面加载后动态添加脚本:
var newScript=document.createElement("script");
newScript.src="script.js";
document.head.appendChild(newScript);
不幸的是,这通常无法直接在主页上生效,因为广告需要在特定位置投放。在这种情况下,解决方法是使用iframe。这就是我在this page右侧所做的工作。