我已經閱讀了很多主題,並嘗試了很多東西,但我無法得到我想要的東西。 我剛剛在頁面末尾移動了我的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