Problem with JavaScript, please help

Discussion in 'HTML & Website Design' started by glorybeme, Oct 29, 2006.

  1. #1
    I want to make a seperate file for Adsense or YPN so that I can include the file on each page, but when I want to make changes to the code, I would only need to access one file. That way I would not have to change 200+ pages.

    I thought I could paste my adsense code into notepad and name it with a .js extension, upload that file to my website, and then add this code into my webpage:

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

    When do that it does not pull the adsense code onto the page. Can someone tell me what I am doing wrong?
     
    glorybeme, Oct 29, 2006 IP
  2. DatR

    DatR Peon

    Messages:
    210
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    the problem is that if you copy the text from adsense straight in, you will have the <script ...> in your .js file and this is why it doesnt work.

    Best way is using something like PHP or ASP to server side include the adsense code. If you still want to use JS to include it then you would so something like this:

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

    and in filename.js put only the text google provides you between the first <script> </script>:

    google_ad_client = "XXXXXXX";
    ...
    google_color_text = "000000";
     
    DatR, Oct 29, 2006 IP
    glorybeme likes this.
  3. glorybeme

    glorybeme Well-Known Member

    Messages:
    814
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Thank you for your reply. I will try what you said. Thanks!
     
    glorybeme, Oct 30, 2006 IP