I have read a lot of topics and tried a lot of stuff but I can't get what I want. I just moved my js code at the end of the page and now I get some errors.
This is how my page looks like:
<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>
In fonctions.js I have my google adsense code:
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;
//-->
}
The idea was to have the same code for adsense at only one place but I can't get it to load after the file fonctions.js
I tried defer="defer", window.onload ...
Any ideas? Thanks
I get this error in Firebug: Error : adsense is not defined
PS: I would like to avoid to use Jquery (to avoid making pages too big)
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>
in fonctions.js if I put the following code, the "ok" is displayed:
function adsense(){
alert ("ok");
}
However if I have this code, the ad is not displayed:
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;
}
My guess is that it's a Google issue... The code cannot be loaded in this way...? If I put the adsense code in the page (below the call - where you do alert('here'); ) it is well displayed... So my adsense code is correct
UPDATE: I have finally changed the solution, I've put the code in a .html file and I include it using php. So it's not in my js file anymore. Thanks for your help anyway.
window.load = function() { adsense(); };<!--from the adsense() function, and//-->also