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

  • SEARCH
  • Home
  • 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 8618385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:05:39+00:00 2026-06-12T06:05:39+00:00

I have a a button that once clicked i show an overlay modal div

  • 0

I have a a button that once clicked i show an overlay modal div and within this div i embed an adsense code. The code is the following:

$('<div />').addClass('lightbox').appendTo('body').show();
    $('<div />').addClass('video_modal').appendTo('body').
                 css('top', '100px').css('left', $(window).width()/2-200+'px').
                 html('<div style="width:100%;height:225px;float:left"><script type="text/javascript"><!--\
        google_ad_client = "ca-pub-4677950456522449";\
        /* Cuadrado_Principal */\
        google_ad_slot = "9996968724";\
        google_ad_width = 300;\
        google_ad_height = 250;\
        //-->\
        </script>\
        <script type="text/javascript"\
        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\
        </script>\
</div>\
                 <div class="preloader"></div>\
                 <div class="preloader_text"Searching...</div>').show();

The question is that preloader and it’s text is shown but not the adsense ad. What’s wrong in my code? I can not understand what’s happening.

Thanks.

  • 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-12T06:05:41+00:00Added an answer on June 12, 2026 at 6:05 am

    My experience says that dynamically adding AdSense is…difficult. Perhaps Google doesn’t allow it and therefor it’s not working. My recommendation is creating a hidden div with the AdSense code and later upon whatever event you’re firing, with jQuery, move the contents of the hidden div to wherever you prefer.

    In this example I’ve added an ID to one of your divs called “googleadgoeshere”, and the hidden div is called “adsense”.

    <html>
    <head>
    <title>Test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    </head>
    <body>
    <p>Hello world</p>
    
    <script type="text/javascript">
    function showAd() {
        $('<div />').addClass('lightbox').appendTo('body').show();
        $('<div />').addClass('video_modal').appendTo('body').css('top', '100px').css('left', $(window).width()/2-200+'px').html('<div style="width:100%;height:225px;float:left" id="googleadgoeshere"></div>');
        $('<div />').addClass('preloader').appendTo('body').show();
        $('<div />').addClass('preloader_text').text('Searching...').appendTo('body').show();
        $('#adsense').show().appendTo('#googleadgoeshere');
    }
    </script>
    
    <div id="adsense" style="display:none">
    <script type="text/javascript">
    <!--
    google_ad_client = "ca-pub-4677950456522449";
    /* Cuadrado_Principal */
    google_ad_slot = "9996968724";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
    </div>
    
    <input type="button" value="Show ad" onclick="showAd()" />
    
    </body>
    </html>
    

    It works for me, let me know if you run in to any trouble!

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

Sidebar

Related Questions

i have a script that once clicked ( a button ) some other thing
I have a 'link' that, when clicked, will show a div full of content.
I have a button that is supposed to close a modal panel and render
I have a button that when clicked will run a stored procedure on a
I have a button that opens a dialog when clicked. The dialog displays a
I have a button that, when pressed, will add a new HTML row. Within
I have multiple clicks, that I have to unbind once clicked on, but I
I have this div that is supposed to be hidden when the page loads
I have a button, Load Team, that, when clicked, I want to have a
I have a button that is within an updatepanel control. The button's click event

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.