Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Adsense in javascript file
Old 03-21-2007, 12:14 PM Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
Hi Guys,

I'm not sure if this is the correct place to ask this question.

I'm trying to create a javascript file (.js) that contains the adsense code that should be placed on my static html file. This way, I can reference the same adsense block in all my pages and whenever I decide to change the colors, dimensions .. etc, I will just go there and make my updates.

The javascript file looks like this:
document.writeln('<script type="text/javascript"><!--');
document.writeln('google_ad_client = " <Adsense ID removed> ";');
document.writeln('google_ad_width = 728;');
document.writeln('google_ad_height = 90;');
document.writeln('google_ad_format = "728x90_as";');
document.writeln('google_ad_type = "text_image";');
document.writeln('google_ad_channel ="7100825086";');
document.writeln('google_color_border = "FFDDDD";');
document.writeln('google_color_bg = "FFDDDD";');
document.writeln('google_color_link = "000000";');
document.writeln('google_color_url = "000000";');
document.writeln('google_color_text = "000000";');
document.writeln('//--></script>');
document.writeln('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');

This works great. The problem happens when I try to surround this code by a table (using script code like document.writeln('<table><tr><td>'); )

when I do that, I found that the table and the ad block are generated as 2 blocks even if the script should be placed inside the table cell (1 block).

Anyone has some ideas?

Moderators, if this is the incorrect place for this question, please feel free to move it ;-)
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by chrishirst; 03-22-2007 at 05:12 PM.. Reason: Removed adsense ID from code
bj_private is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-22-2007, 05:20 PM Re: Adsense in javascript file
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
moving to javascript
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2007, 07:52 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
Thanks Chris. I thought it maybe the wrong place to ask this question
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-22-2007, 09:47 PM Re: Adsense in javascript file
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I'm not necessarily sure that the answer is a Javascript one. I just put my adsense code into an include file (usually a layout file) and adjust it from there.

In other words, SSI may hold your answer, not necessarily Javascript.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 03-23-2007, 07:00 AM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
BillyRandyFreddieJoeFloydBob,

can you please post a sample? of how you can do it. I don't necessarily need this to be using Javascript.

nice name BTW
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 09:33 AM Re: Adsense in javascript file
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
<!--#include virtual="/folder/file_with_adsense_code.ext" -->
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-23-2007, 10:22 AM Re: Adsense in javascript file
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
What Hirst said. You can use a regular HTML file for the include as long as it's part of an SSI file (e.g. something.shtml, something.asp, something.php).

Thanks for noticing my name. I was just feeling goofy one night so I stuck it up.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 03-23-2007, 12:18 PM Re: Adsense in javascript file
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
That's the same thing I did with mine. Yours isn't working because it's not correct.

On your page add the JS call to your js file (made from the adsense code) like this:
Code:
<script type="text/javascript" src="/path/to/your/adsense.js"></script>
Now, in the JS file you're going to save, you need to do this:
Code:
<!--

google_ad_client = " <Adsense ID removed> ";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="7100825086";
google_color_border = "FFDDDD";
google_color_bg = "FFDDDD";
google_color_link = "000000";
google_color_url = "000000";
google_color_text = "000000";

//-->
Then, you're all set.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-23-2007, 02:00 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
Chris,

thanks, but I have static html files and the statement:

<!--#include virtual="/folder/file_with_adsense_code.ext" -->

didn't work for me.


Deb,
I successfully managed to put the google adsense code in a javascript and it's working just fine.

The problem is when I try to put a table around the adsense code (to make the adsense block look wider than 728 px). I try to do it like this:

in the adsense.js file:

Code:
 
/* Begin Google Adsense code */
document.writeln('<TABLE bgcolor="FFDDDD" WIDTH=777 BORDER=1 bordercolor="728FB1" CELLPADDING=0 CELLSPACING=0><tr><td><center>');
document.writeln('<script type="text/javascript"><!--');
document.writeln('google_ad_client = "publisher code";');
document.writeln('google_ad_width = 728;');
document.writeln('google_ad_height = 90;');
document.writeln('google_ad_format = "728x90_as";');
document.writeln('google_ad_type = "text_image";');
document.writeln('google_ad_channel ="7100825086";');
document.writeln('google_color_border = "FFDDDD";');
document.writeln('google_color_bg = "FFDDDD";');
document.writeln('google_color_link = "000000";');
document.writeln('google_color_url = "000000";');
document.writeln('google_color_text = "000000";');
document.writeln('//--></script>');
document.writeln('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
document.writeln('</center></td></tr></table>');
/* End Google Adsense code */
In the .html file:
Code:
 
<!-- Begin Google Adsense code -->
<script TYPE="text/javascript" src="script/adsense.js"></script>
<!-- End Google Adsense code -->
Please notice that if I put the <table> code inside the html file it works fine. But I need to put it in the .js file to make sure I can change it whenever I want easily.

To take a look at the problem, just see this page http://www.smartbro.com/index1.html

What I need to accomplish is this http://www.smartbro.com/index.html (the adsense block at the top)

Any ideas why this happen?
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by bj_private; 03-23-2007 at 02:03 PM..
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 02:05 PM Re: Adsense in javascript file
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
Change the writeIn to just
write

It should be
document.write

See if it helps.

If it still doesn't work, give me about a hour and I'll tweak the codes on my site and post it here for you. OK?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-23-2007, 02:18 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
Thanks for the quick reply. I've tried to replace writeln with write, but the google adsense just disappears ... that's weird!!

I would be grateful if you could take a look at the code on my website. thanks in advance :-)
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 02:52 PM Re: Adsense in javascript file
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
doh. The double quotes need to be escaped. I have a major headache today with all of the thunder and rain ... it's why I didn't catch this earlier.

Also, you had that as writeln (lowecase "L")
That's not even correct.

It's document.write(' this line blah blah blah ');

OK, here's the corrected code. Try it now and see if we strike pay dirt.
Code:
document.write('<TABLE bgcolor=\"FFDDDD\" WIDTH=777 BORDER=1 bordercolor=\"728FB1\" CELLPADDING=0 CELLSPACING=0><tr><td><center>');
document.write('<script type=\"text/javascript\"><!--');
document.write('google_ad_client = \"publisher code\";');
document.write('google_ad_width = 728;');
document.write('google_ad_height = 90;');
document.write('google_ad_format = \"728x90_as\";');
document.write('google_ad_type = \"text_image\";');
document.write('google_ad_channel =\"7100825086\";');
document.write('google_color_border = \"FFDDDD\";');
document.write('google_color_bg = \"FFDDDD\";');
document.write('google_color_link = \"000000\";');
document.write('google_color_url = \"000000\";');
document.write('google_color_text = \"000000\";');
document.write('//--></script>');
document.write('<script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>');
document.write('</center></td></tr></table>');
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-23-2007, 04:20 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
Deb,

thanks for your reply, but I don't think you understand my problem correctly. The code that I've sent you earlier with (writeln) IS working. The only problem with it (which I'm trying to solve here) is that I get 2 boxes. See attached screenshot (screenshot #1). When I don't write the table code inside the .js file, and write it inside the html file, the output comes as (screenshot #2) which is what I want.

I'm trying to find out why the table is not displayed correctly when written inside the .js file.
Attached Images
File Type: jpg screenshot1.jpg (86.6 KB, 3 views)
File Type: jpg screenshot2.jpg (54.5 KB, 2 views)
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 04:23 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
BTW, I tried your updated code and still doesn't work.
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 04:44 PM Re: Adsense in javascript file
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
OK, beats me then. I'm not real clear today anyway (have migraine )
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-23-2007, 05:03 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
LOOOL! The problem is quite confusing. Isn't it?
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 05:12 PM Re: Adsense in javascript file
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
Yeah, it's confusing when headache stops the thought process altogether.
I'll look at this tomorrow when my brain isn't so foggy.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-23-2007, 05:23 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
ok, I'll wait then.

thank you very much Deb!!
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Old 03-23-2007, 05:29 PM Re: Adsense in javascript file
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
You're welcome, Tony.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-24-2007, 03:54 PM Re: Adsense in javascript file
bj_private's Avatar
Extreme Talker

Latest Blog Post:
Miss January 2009 . . . Great!
Posts: 199
Name: Tony
Trades: 0
Anyone can help me with this guys?
__________________
Tony Sticks

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
bj_private is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Adsense in javascript file

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 3.68092 seconds with 13 queries