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 6609725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:45:06+00:00 2026-05-25T19:45:06+00:00

I would like to place a javascript (adsense) code inside the post (not above

  • 0

I would like to place a javascript (adsense) code inside the post (not above or after the post). It will be a HTML page.

Is there any way i can put my adsense code in external Js file and i will use one function to display it.
adsense code looks something like

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_host = "pub-xxxxxxxxxxxxxxxx";
google_ad_slot = "xxxxxxxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

So if i call a function CallMe() which will start showing ad wherever i have used the function. In future if i would like to replace ad code with another code then i dont want to go to each post and replace it. I will just replace the adcode from js file.

I am a newbie and have just started learning JavaScript so i am really not aware if it can be done or not.

Any suggestion ?

  • 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-05-25T19:45:07+00:00Added an answer on May 25, 2026 at 7:45 pm

    Create file called AdSense.js with the following code:

    google_ad_client = "pub-xxxxxxxxxxxxxxxx";
    google_ad_host = "pub-xxxxxxxxxxxxxxxx";
    google_ad_slot = "xxxxxxxxxx";
    google_ad_width = 336;
    google_ad_height = 280;
    function ApplyAdSense() {
        var oScript = document.createElement("script");
        oScript.type = "text/javascript";
        oScript.src = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
        document.getElementsByTagName("head")[0].appendChild(oScript);
    }
    

    Now whenever you want adsense in your code, first include the file:

    <script type="text/javascript" src="AdSense.js"></script>
    

    Then call the function:

    <script type="text/javascript">
        ApplyAdSense();
    </script>
    

    This way, until you call the function nothing happens.. and you can also comment the code inside the function to disable adsense throughout all your site.

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

Sidebar

Related Questions

I am new to Javascript & relatively new to HTML. I would like to
I would like to place my div below the list, but actually it is
I would like to place the names of the dependencies in a text file
I Have a canvas and would like to place silverlight elements within that canvas
Should be simple but I couldn't find the answer, I would like to place
I would like to move a file or folder from one place to another
Due to some limitations on the place files are being placed, I would like
I would like to implement a API of JavaScript that sort of resemble a
I have a jsFunction that I am running, and would like javascript to be
I would like to give my CSS and javascript files far-future headers and add

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.