Forum Moderators: open
I found some script on another forum when I was searching for how to do this. The script is as follows:
{if $current_location == $http_location}
Google AdSense Goes Here
{/if}
The problem is I cannot get that to work with Adsense because the Adsense code itself has 2 different javascript codes in it.
Will the above script work? Am I just putting it in wrong? Or do I need a different script all together?
I would have thought that the preferred method would be to do this server-side with PHP or similar, that way completely eliminating the Google code from your secure pages. If using JS, then the code will still be there, just not executed.
In PHP I would have thought you could examine the contents of $_SERVER["HTTPS"] (the exact value depends on IIS / Apache)
However, since this is the JS Forum, may be you can examine location.href to see if "http:" is at the start of the URL ...?
if (location.href.indexOf('http:') == 0) {
//Google AdSense Goes Here
}
I would have thought that the preferred method would be to do this server-side with PHP or similar, that way completely eliminating the Google code from your secure pages.
Agreed, or if by "two javascript codes" you mean the secure version or the non-secure version of adSense, you can continue running adSense on the secure pages by pointing to the secure version (but it will slow it down even more.) You can use the HTTPS environment variable on linux:
if (! $ENV{'HTTPS'} or ($ENV{'HTTPS'} =~ /off/i)) {
## adSense code
}
else {
## secure adSense code OR eliminate this else completely
}
It looks like the code you gave me does work as far as not showing the ad on a secure page. I am still getting the "secure and unsecure items" pop up box though because the Adsense code is trying to get the unsecure Google link:
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"
What do I need to do in this case?
I don't know if this will get rid of the security warning though...
I am still getting the "secure and unsecure items" pop up box though because the Adsense code is trying to get the unsecure Google link:
Is this in the HEAD section? May be you can apply the same IF() principle, but have a document.write('<script src=".../show_ads.js" type="text/javascript"></script>') ....? Hhhmm, would that work?!