这让我很头疼,一整天都在追逐它。我们有一个广告服务器调用我们网站上的脚本,然后插入代码。
例如 在 iframe 中调用的广告服务器页面:
<html>
<head><title></title></head>
<body>
<script src="http://adserver/ad?s=728x90"></script>
</body>
</html>
上面脚本调用返回的javascript:
document.write('<script type=\'text/javascript\' src=\'http://partner.googleadservices.com/gampad/google_service.js\'>\n');
document.write('</script>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GS_googleAddAdSenseService("ca-pub-xxxxxxxxxxxxxxxxxxx");\n');
document.write('GS_googleEnableAllServices();\n');
document.write('</script>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GA_googleUseIframeRendering();\n');
document.write('</script>\n');
document.write('\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GA_googleFillSlotWithSize("ca-pub-xxxxxxxxxxxxxxxxxx", "Global_728x90", 728, 90);\n');
document.write('</script>\n');
这会将 Google Ad Manager 广告插入我们的页面。问题是该代码在 IE 7 和 8 中不起作用,但在 Chrome、Firefox、Safari 等中运行良好。
IE 返回的“错误”是“预期的对象”,通过 IE 的“开发人员工具”运行它也无济于事。
我已经尝试了很多方法来让它工作,将
似乎每当运行 GS_ 或 GA_ 函数时都会发生错误,所以我怀疑 IE 试图阻止外部脚本写入页面?
任何人都可以阐明错误发生的原因或解决方案吗?
谢谢
最佳答案
我认为这仅仅是因为 Chrome、Firefox、Safari 等浏览器速度更快。在执行依赖于它的脚本之前,他们正在下载文件 http://partner.googleadservices.com/gampad/google_service.js
,而此时 IE 仍在提取文件。
也许您可以在您自己的某个地方的 js 中包含该 js 文件的内容?
关于Javascript document.write 在 IE 8 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3358887/