Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: open

Message Too Old, No Replies

Detecting iframes / javascript enabled browsers

How to tell if a browser doesn't support BOTH

     

Bluesplinter

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

10+ Year Member



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)?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month