Jump to content



Photo
- - - - -

javascript help


  • Please log in to reply
4 replies to this topic

#1 _Ray

_Ray

    Executioner

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,107 posts

Posted 09 February 2011 - 09:11 PM

Hey,

If anybody is knowledgeable, I really could use some help here.

I'm trying to write a script that makes it so that when using a screen width of 1280 or lower, Google shows one ad at the top of the page. With screen widths over 1280, it shows 2 ads along the side of the screen.

I've checked it several times and I don't know what I've done wrong (but I'm also a beginner). The script works flawlessly in all versions of Firefox for both high and low res (I checked with FF 2.0, 3.0, 3.5, and 3.6) but in IE6 and IE8 while displaying almost correctly at the high resolution, it gets completely screwed up at the low resolution.

Basically I'm just using Javascript to insert HTML comment tags around the ads that I don't want to appear for that resolution.








<!-- Test run of Google AdSense -->
<!-- One ad floats left, one floats right, the rest of the body is center aligned in between (high res only) -->
<!-- There are 3 ads, scripting makes it so that 2 appear on the sides with a screen width above 1280 pixels, and below 1280 pixels just one appears across the top -->


<script type="text/javascript">
<!--
var skip1 = "<!--";
if ( screen.width <= 1280 )
{
document.write (skip1);
}
//-->
</script>

<div style=" float:left; font-size:7pt; color:#777; ">
Advertisement<br />
<script type="text/javascript"><!--
google_ad_client = "pub-9736870014804453";
/* 160x600, created 2/2/11, left side homepage */
google_ad_slot = "6021069285";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googl...d/show_ads.js">
</script>
</div>

<div style=" float:right; font-size:7pt; color:#777; ">
Advertisement<br />
<script type="text/javascript"><!--
google_ad_client = "pub-9736870014804453";
/* 160x600, created 2/2/11, homepage */
google_ad_slot = "3502793671";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googl...d/show_ads.js">
</script>
</div>


<script type="text/javascript">
<!--
var skip2 = "-->";
if ( screen.width <= 1280 )
{
document.write (skip2);
}
//-->
</script>


<script type="text/javascript">
<!--
var skip3 = "<!--";
if ( screen.width > 1280 )
{
document.write (skip3);
}
//-->
</script>

<div style="font-size:7pt; color:#777;">
<center>
Advertisement<br /><br />
<script type="text/javascript"><!--
google_ad_client = "pub-9736870014804453";
/* low res top ad */
google_ad_slot = "4610054252";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googl...d/show_ads.js">
</script>
</center>
</div>

<script type="text/javascript">
<!--
var skip4 = "-->";
if ( screen.width > 1280 )
{
document.write (skip4);
}
//-->
</script>


<!-- End of Adsense side banners -->

Apparently it doesn't work in Opera, Chrome, or Safari either and the code doesn't validate as XHTML so there is definitely something wrong. :(
Posted Image

#2 Gerard

Gerard

    Underboss

  • Administrators
  • 3,873 posts

Posted 11 February 2011 - 12:58 PM

Wouldn't it be simpler to have the adverts there at all times, and use CSS to show/hide them?

You could have both sets as display:none; then use JS to decide which bit of CSS to use to make one set of ads appear.

Grand Theft Wiki Manager

And not a single fuck was given that day.


#3 _Ray

_Ray

    Executioner

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,107 posts

Posted 17 February 2011 - 09:25 PM

Sorry I didn't get back here, but yes, that's what I did.

http://www.codingfor...d.php?p=1051509
Posted Image

#4 Masked Marauder

Masked Marauder

    Fairweather Fiend

  • Members
  • PipPip
  • 172 posts

Posted 17 March 2011 - 04:34 PM

I used to utilize CSS/dhtml to hide advertising banners from a "free" website hosting service that I used to use. I just put them on a separate div layer and kept it hidden at all times. *L* I think that server-side scripting killed that plan though.

#5 sanjai

sanjai

    Nobody Special

  • Members
  • 3 posts

Posted 02 September 2011 - 05:19 AM

hi thanks for your information i am new to this forum




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users