homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Detecting iframes / javascript enabled browsers
How to tell if a browser doesn't support BOTH
Bluesplinter




msg:1477772
 8:15 pm on Aug 7, 2003 (gmt 0)

I run Google AdSense ads on my site, and Google Uses javascript and iframes to load the ads. However, I have substantial traffic that either has javascript disabled, or use older browsers that either don't support iframes or js (or both).

So, how can I detect if either iframes or javascript doesn't work in a browser, and load a default static banner in those browsers?

In pseudocode:

if (js == true AND iframes = true)
... {load AdSense code}
else
...{load a default banner}

Keep in mind you can't tamper with the AdSense code itself. Thanks!

 

Purple Martin




msg:1477773
 2:57 am on Aug 8, 2003 (gmt 0)

The first thing that springs to mind is that if the script (pseudocode above) is being executed then JavaScript must be enabled.

So you only need to detect iframes in the script, and you also need to put the default banner in a <noscript> tag.

Revised pseudocode:

<script>
if (iframes == true) {
...(load AdSense code)
} else {
...(load a default banner)
}
</script>
<noscript>
...(a default banner)
</noscript>

Bluesplinter




msg:1477774
 8:40 pm on Aug 8, 2003 (gmt 0)

Thanks, Purple, that makes sense. So now I just need to figure out how to detect iframes capability, before the AdSense iframe is actually present.

I suppose I could try to insert a small iframe of my own, and if it worked, then I would know the browser supports iframes, but that seems awfully round-about. Anyone know of a better way (that doesn't rely on user-agent strings)?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved