_Ray Posted February 9, 2011 Share Posted February 9, 2011 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.googlesyndication.com/pagead/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.googlesyndication.com/pagead/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.googlesyndication.com/pagead/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. Link to comment Share on other sites More sharing options...
Gerard Posted February 11, 2011 Share Posted February 11, 2011 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. Link to comment Share on other sites More sharing options...
_Ray Posted February 17, 2011 Author Share Posted February 17, 2011 Sorry I didn't get back here, but yes, that's what I did. http://www.codingforums.com/showthread.php?p=1051509 Link to comment Share on other sites More sharing options...
Masked Marauder Posted March 17, 2011 Share Posted March 17, 2011 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. Link to comment Share on other sites More sharing options...
sanjai Posted September 2, 2011 Share Posted September 2, 2011 hi thanks for your information i am new to this forum Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now