Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:28:22+00:00 2026-06-01T23:28:22+00:00

Okay, so I’m working on a responsive site and I’m trying to handle Adsense

  • 0

Okay, so I’m working on a responsive site and I’m trying to handle Adsense in the best way possible that doesn’t get me banned! What I’d like to do is use jQuery to add in my Adsense code only if the browser width is less than 533px. This way, I can display a smaller ad that will fit the window properly and not break the layout. I’m having some trouble getting the Adsense javascript added though. This works:

(function($){
//detect the width on page load
$(document).ready(function(){
var current_width = $(window).width();
//do something with the width value here!
if(current_width < 533){
        $('.ads').prepend("THIS IS WHERE I WANT THE ADSENSE CODE TO GO");
}
});

But when I include my Adsense code to replace THIS IS WHERE I WANT THE ADSENSE TO GO, it doesn’t. This is the Adsense code:

<script type="text/javascript"><!--
google_ad_client = "ca-pub-1234567890";
/* Test Ad */
google_ad_slot = "1234567890";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

I’ve also tried to include the Adsense javascript code in a .html file and use jQuery.get and jQuery.getScript for a .html and .js file. I just can’t get it to work.

I could do it with a simple PHP header detect, but I want the ads to display based on width, not device type.

Anybody know how this can be done?

(Reposted as no replies to previous question)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:28:24+00:00Added an answer on June 1, 2026 at 11:28 pm

    The problem you’re facing is that Google doesn’t really support AdSense ajax. The normal way of including adsense code uses the URL of the page where it lives in order to render the right content.

    Now, suppose you could reduce the adsense code to a particular URL. You could do something like this:

    // note, this url is just a suggestion, not something that will likely work 
    
    var url = 'http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-1234567890&ad_slot=1234567890&ad_width=250&ad_height=250';
    
    var adsContainer = $('.ads');  // though, if there's only one, use id, not class
    
    $.ajax({
    type:'GET',
        url:url,
        async:true,
        success:function(html) {
            adsContainer.html(html);
            return false;
        },
        error: function(html) {
          adsContainer.html('SOME DEFAULT AD MESSAGE');
          return false;
        } 
    });
    

    But I think this is almost assuredly the kind of thing that will get you in trouble with Google.

    Google used to have an adsense ajax program:

    https://developers.google.com/adsense-for-ajax/

    But it is now “unavailable”. The reason you can’t put your code in an external .html or .php file and ajax on your own server is that the javascript doesn’t get executed by an engine on the client side by the ajax call. You are injecting raw javascript into a page that has already been interpreted by the javascript engine.

    Could you use node.js or some kind of server side javascript parser to serve your .html file? Maybe, but that’s a lot to solve this problem.

    My advice is this: include multiple, smaller ads that will look good if stacked on a big page, or tiled if crammed together on a small page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, I´m working on a website right now that shows information about parts of
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay, so I'm working on a java server for an Apps backend, it must
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay, here's the rundown. I'm developing a video hosting site with PHP and jQuery
Okay so the title may be a bit misleading. What I am trying to
Okay, I'm trying to reverse engineer a feature on a website I found -
Okay, I'm a little fuzzy on how this works or if it's possible. I
Okay so here is what I'm trying to accomplish. First of all below table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.