-
Is this code ok?
I am trying to display Adsense ads conditionally, is there anything wrong with the syntax of this code?
<script type="text/javascript">
if (asppg_showGoogleAds)
{
document.write("<sc"+"ript type='text/javascript' src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></scr"+"ipt>");
}
</script>
Thanks
-
You try this code:
Code:
if (asppg_showGoogleAds) {
var sc = document.createElement('script');
sc.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
sc.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(sc);
}
-
Thank you pitiko, I tried it but it does not work :(
-
There shouldn't be a problem with that javascript, but why are you splitting it up into different substrings?
Try this, it should do the same thing:
Code:
if (asppg_showGoogleAds) {
var script = "<script type=\"text/javascript\" src='http://pagead2.googlesyndication.com/pagead/show_ads.js'><\/script>";
document.write(script);
}