Site Reference Forums

You are not logged in.

#1 2008-03-19 18:39:47

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Auto change background color w/adsense

If I put Google ads on each page with server side inclusion, can I make the background auto change on each page to the backgound color of that page?

Proboard forums puts google ads on their forums that many many people use for their forum, and no matter what color I make the forum the Google ads match the background. How?


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#2 2008-03-20 03:20:06

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2505
I've been thanked 53 times.

Thank me Website
Buy me a beer

Re: Auto change background color w/adsense

A google ad code snippet looks like this

Code: javascript

<script type="text/javascript"><!--
google_ad_client = "pub-8765049832089938";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text";
google_ad_channel = "0066235252";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "719700";
google_color_text = "000000";
google_color_url = "3D81EE";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


See all those variables defining colour?

You can change those through either a server-side language (like PHP) when the page is requested, or by using javascript.

If, like me, you use the jquery framework, it's easy to pull back the colour properties of a DOM element that has it's colour defined by CSS.

For example, if the body font color is green (color:#009900) doing

Code: javascript

var myColour = $("body").css("color");

assigns either "#009900" or "009900" to the variable (haven't checked which, but a simple replace would sort it out! if it did have a # in it).

If you're not using jquery, then you can still get the css properties, it just takes a few more lines of code and doesn't run as quickly.

then modify the google code to bring the text colour inline with the body colour in myColour

Code: javascript

<script type="text/javascript"><!--
google_ad_client = "pub-8765049832089938";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text";
google_ad_channel = "0066235252";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "719700";
google_color_text = myColour;
google_color_url = "3D81EE";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Now taking free-lance inquiries; Please contact me for more details
Xeneco - SEO and Design Services
Web 20 - Web Apps
Nothing's Impossible, just let me think about it for a while....

Online

 

#3 2008-03-20 11:43:03

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

Buy I would put myColor on the background, right? I'll give it a shot, thanks.


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#4 2008-03-20 18:09:18

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

Is this the entire java script::

var myColour = $("body").css("color");

?

Thanks


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#5 2008-03-21 08:33:15

aknet47
Member
From: vienna
Registered: 2006-09-14
Posts: 225
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

Hi beatledave,

I am currently using this technique on a dynamic webpage and I have choosen the following solution:
Half of the work could be done via the adsense-account(styling of the ads).

  1. I am defining ads for the different styles over the google-adsense-styling functions
  2. after that I am saving the designed ad under the name of my template
  3. Next step is to create a php-file with a switch that manages to display the correct ad for the style the users have choosen
  4. Last step   include the script into the code-file responsible for the output of the page.

Last edited by aknet47 (2008-03-21 08:37:05)


I´ve got a blog

Offline

 

#6 2008-03-27 17:44:36

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

OK, so can I do this:

<.script type="text/javascript">var myColour = $("body").css("color");
</script.>


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#7 2008-03-28 03:53:31

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2505
I've been thanked 53 times.

Thank me Website
Buy me a beer

Re: Auto change background color w/adsense

beatledave wrote:

OK, so can I do this:

<.script type="text/javascript">var myColour = $("body").css("color");
</script.>

only if you include the jquery library before hand


Now taking free-lance inquiries; Please contact me for more details
Xeneco - SEO and Design Services
Web 20 - Web Apps
Nothing's Impossible, just let me think about it for a while....

Online

 

#8 2008-03-28 10:14:50

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

That cost money and I'm not sure what I'm doing. Someone said, "You can change those through a server-side language "

The google ads wil be in an SSI, so can I still use this in an SSI? If so, how would I write it? Can I really put a server side code inside a server side  code? I hate to just go with a white background on the pages, even though most pages are white. I wish Google had a transparent background and border color. I'm feeling over my head.


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#9 2008-03-28 10:42:21

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2505
I've been thanked 53 times.

Thank me Website
Buy me a beer

Re: Auto change background color w/adsense

beatledave wrote:

That cost money and I'm not sure what I'm doing. Someone said, "You can change those through a server-side language "

jquery is free, light weight, super fast and easy to use

you can change your ad background color with a server side language

"server side includes" is not a server side language

a server side language is something like PHP, ASP, Ruby, Java (not javascript) etc etc - or anything where you can get the language to make a decision and change the value of a variable before sending it to the browser


Now taking free-lance inquiries; Please contact me for more details
Xeneco - SEO and Design Services
Web 20 - Web Apps
Nothing's Impossible, just let me think about it for a while....

Online

 

#10 2008-03-28 10:58:19

MarkCCDC
Moderator
From: Deland, FL
Registered: 2005-10-25
Posts: 1221
I've been thanked 16 times.

Thank me Website
Buy me a beer

Re: Auto change background color w/adsense

BD:

Yes, you can still include the Google ads with a Server Side Include.

There are two common types of includes (not sure if there are more in other languages or whatever).

Server Side Includes (SSI) - Probably most common is the PHP Include. Before the content is delivered to the browser, the PHP is parsed and the code is interpreted and executed. Including a file is done BEFORE the page is rendered in the browser, so you can manipulate content and code that is included with a SSI by using the next type of include.

Client Side Includes (CSI)- Like Javascript. These are rendered at the same time the rest of the page is, so it doesn't know you are even using an SSI.

Of course, there are ways to change your Google ads either way. Northie provided an excellent example if you want to go the CSI (hehe, not Crime Scene Investigator) route, but you can do it all in PHP if you wanted to. Only difference is, Northie's example is probably the easiest and fastest whereas you might need a little more PHP know-how - I don't know what you know how to do, so I don't know which way is easiest for you.

Also, Northie's code is completely dynamic, so it will always get the background color that is set by the CSS. I don't know how to duplicate that functionality in PHP (I guess some regular expressions and magic would work lol) but I'm sure it can be done.


Mark
Has my advice helped? Thank Me!

Offline

 

#11 2008-03-28 11:16:36

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2505
I've been thanked 53 times.

Thank me Website
Buy me a beer

Re: Auto change background color w/adsense

Javascript and CSS Colours using javascript and jquery

taking a code excerpt verbatim from

http://docs.jquery.com/CSS/css

put this in notepad, save as js-test.htm and view it in a browser (doesn't need to go anywhere near a webserver as it's all client side) and click on the coloured squares

Code: html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
 
  <script>
  $(document).ready(function(){
   
    $("div").click(function () {
      var color = $(this).css("background-color");
      $("#result").html("That div is <span style='color:" + color + ";'>" + color + "</span>.");
    });

  });
  </script>
  <style>
  div { width:60px; height:60px; margin:5px; float:left; }
  </style>
</head>
<body>
  <span id="result"> </span>
  <div style="background-color:blue;"></div>
  <div style="background-color:rgb(15,99,30);"></div>
  <div style="background-color:#123456;"></div>
  <div style="background-color:#f11;"></div>
</body>
</html>

Now taking free-lance inquiries; Please contact me for more details
Xeneco - SEO and Design Services
Web 20 - Web Apps
Nothing's Impossible, just let me think about it for a while....

Online

 

#12 2008-03-28 11:33:04

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

Done. Works fine. I don't know what to do next. It's saved as html, is that OK? I can easily change that, in my rush I just typed out html.


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#13 2008-03-28 16:03:15

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

I'm in limbo here. Am I suppose to use this:
var myColour = $("body").css("color");
somewhere?

Or will the test code above change my google ads background? What do I put in the google ad background color="_"? Or were you testing my server?

help.... pls...^5


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 

#14 2008-03-28 18:28:12

Northie
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2505
I've been thanked 53 times.

Thank me Website
Buy me a beer

Re: Auto change background color w/adsense

I'm not going to do this for you - there's enough information on this page for someone with no knowledge of HTML and javascript to accomplish the task you wish to complete

How you do this with javascript has nothing to do with how you want to set up your server side includes

Here are some steps that i hope to be foolproof

1 - download the packed version of jquery from the jquery website (it might redirect you through google code - but that's ok)

2 - name this file "jquery.js" and upload it to the root of your website

3 - reference the script in all pages that you want to be messing around with (eg by putting <script type='text/javascript' src='/jquery.js'></script> in the <head> section of your page

4 - add this to the <head> section of those pages

Code: javascript

<script type='text/javascript'>
ad_back_color = "";
$(function(){
     ad_back_color = $("body").css("background-color");
});
</script>


5 - get your adsense code looking like the example i gave in post#2 - this is the old style, so you may have to write it out by hand

6 - replace the value of the background color in the adsense code with the variable you just created (ad_back_color)

7 - test


Now taking free-lance inquiries; Please contact me for more details
Xeneco - SEO and Design Services
Web 20 - Web Apps
Nothing's Impossible, just let me think about it for a while....

Online

 

#15 2008-03-28 18:41:08

beatledave
Member
From: Ohio USA
Registered: 2004-11-17
Posts: 670
I've been thanked 0 times.

Thank me Website

Re: Auto change background color w/adsense

Thanks.


THE BEATLES ARE FOREVER!
http://beatlesnumber9.com

Offline

 
Never
Sponsored Results


Board footer

Powered by PunBB
© Copyright 2002–2008 Rickard Andersson