954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript check iframe mobile support

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.

zimboden
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: