我已经阅读了很多主题,并尝试了很多东西,但我无法得到我想要的东西。 我刚刚在页面末尾移动了我的js代码,现在我收到了一些错误。在加载页面后加载javascript
这是我的网页看起来像:
<html>
<head>
bla bla
</head>
<body>
bla bla
<div class="advertising">
<script type="text/javascript" defer="defer">
window.onload = adsense();
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<script language="javascript" type="text/javascript" src="fonctions.js"></script>
</body>
</html>
在fonctions.js我有我的谷歌的AdSense代码:
function adsense(){
<!--
google_ad_client = "pub-xxxxx";
/* 120x600, date de création 11/06/11 */
google_ad_slot = "xxxxx";
google_ad_width = 120;
google_ad_height = 600;
//-->
}
当时的想法是对的AdSense相同的代码只有一个地方,但我不能让它加载后的文件fonctions.js
我试过推迟=“推迟”,window.onload ...
有什么想法? 感谢
我得到这个错误在Firebug: 错误:没有定义的AdSense
PS:我想避免使用jQuery(避免使页面过大)
UPDATE:
<script type="text/javascript" defer="defer">
(function() { // 'sandbox' javascript pattern to prevent clobbering
// global namespace
var executeProxy = function() {
if (typeof adsense === 'function') { // adsense is configured
adsense();
} else { // adsense is not configured;
// therefore, try again later
setTimeout(executeProxy, 50);
}
};
executeProxy();
}());
</script>
<script language="javascript" type="text/javascript" src="fonctions.js"></script>
中,如果我把下面的代码fonctions.js
, “确定” 显示:
function adsense(){
alert ("ok");
}
但是,如果我有这样的代码,不显示广告:
function adsense(){
google_ad_client = "pub-xx";
/* 120x600, date de création 16/04/11 */
google_ad_slot = "xxx";
google_ad_width = 120;
google_ad_height = 600;
}
我的猜测是,这是谷歌的问题...该代码不能以这种方式加载中...? 如果我把AdSense代码的页面(调用下面 - 在你做警报(“这里”);)这是很好的展示......所以我的AdSense代码是否正确
更新: 我有终于改变了解决方案,我把代码放入了一个.html文件,并且我使用php来包含它。所以它不再在我的js文件中。 无论如何感谢您的帮助。
_你有什么错误? – SLaks
错误:未定义adsense – remyremy
这样做 - 'window.load = function(){adsense(); };' – treecoder