zimboden 0 Newbie Poster

How to detect if a browser supports iFrames?

<script type="text/javascript" >
  
var e = document.createElement("iframe");
 
  if('src' in e){
    	alert("Your browser supports IFRAMES");
    }else {
    	alert("Your browser DOES NOT support IFRAMES");
    
    }
</script>

WHen you use createElement(), if you pass it 'iframe' it will contain specific iframe properties, like src, frameBorder, contentWindow etc. I used the above script to test for iframe support BEFORE the page loads, so I can redirect the page to the iframe url instead of loading the iFrame.

Blackberry phone apparently have some models with browsers that don't support iFrames and there may be other phones with similar browsers.

Hope this is helpful.

I checked it on Safari 5.0.4 and Internet Explorer 8.0, but not, ironically, with a Blackberry, since I own an iPhone. The way I checked was that I passed a fictious element name 'zyzxz' and this element object does not contain those special properties that only iframe objects seem to possess.

Assuming this actually works on a Blackberry, I believe this is a preferred method for checking compatibility rather than relying on browser-sniffing.