私は多くのトピックを読み、多くのことを試しましたが、私が望むものを得ることができません. ページの最後に js コードを移動したところ、エラーが発生しました。
これは私のページがどのように見えるかです:
<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 には、Google 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;
//-->
}
アイデアは、アドセンスの同じコードを1か所だけにすることでしたが、ファイルfonctions.jsの後にロードできません
defer="defer"、window.onload を試してみました...
何か案は?ありがとう
Firebug でこのエラーが発生します: エラー: adsense が定義されていません
PS: Jquery の使用は避けたい (ページが大きくなりすぎないようにするため)
アップデート:
<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 に以下のコードを入れると「ok」が表示されます。
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;
}
私の推測では、それは Google の問題だと思います...この方法ではコードを読み込めません...? ページにアドセンス コードを配置すると (呼び出しの下 - alert('here');を実行する場所)、適切に表示されます...したがって、私のアドセンス コードは正しいです
更新: 最終的にソリューションを変更しました。コードを .html ファイルに入れ、php を使用してインクルードしました。そのため、もうjsファイルにはありません。とにかく助けてくれてありがとう。