Gary Davis' Blog

DotNET/PayPal Development and other Techie Stuff
posts - 45, comments - 139, trackbacks - 0

How to Suppress Google AdSense (Syndication) for SSL Https Pages

Google AdSense is not supported for https (see here). If you attempt to use it on an SSL page, you will see this warning in IE8.Image1 The user would have to click No to allow the request (for a .js file in this case) to complete. Answering Yes will block it (the wording seems backwards from what you’d expect).

Some postings I saw said to change the .js url in the script to use https://pagead2.googleadservices.com/pagead/show_ads.js but while this will work for this one .js file, the script then attempts to pull in other .js files using http so you still get the warning popup.

The best solution is to not let the warning pop up on your secure pages.

This is the standard AdSense code:

<script type="text/javascript">
    if ("http:" == document.location.protocol) {
     google_ad_client = "pub-1234567890123456";
     google_ad_slot = "1234567890";
     google_ad_width = 728;
     google_ad_height = 90;
     google_ad_format = "728x90_as";
    }
</script>

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

This is the new version that will suppress the AdSense code and prevent the popup on your SSL pages. Simply insert the document.write statement and remove the second script.

<script type="text/javascript">
    if ("http:" == document.location.protocol) {
     google_ad_client = "pub-1234567890123456";
     google_ad_slot = "1234567890";
     google_ad_width = 728;
     google_ad_height = 90;
     google_ad_format = "728x90_as";
     document.write(unescape(
        "%3Cscript src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript' %3E%3C/script%3E"));
    }
</script>

This fix uses the existing conditional block for non-SSL pages that initializes some google_ad variables to also emit a <script> element to pull in the necessary show_ads.js file. For SSL pages, the variables will not be initialized and the script will not be emitted for the page.

Feedback

Gravatar

# re: How to Suppress Google AdSense (Syndication) for SSL Https Pages

Will this also eliminate the lock going from green to yellow or in IE unlocked?

Cheers,
D.
11/28/2012 7:01 PM | Dar
Gravatar

# How To Remove

I am trying to remove https://pagead2.googlesyndication.com because every time I try to put on a new Youtube video, the website pops up. I need step by step. Please help me out!
5/16/2014 8:30 AM | Kate Hack

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 4 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET