Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect support for HTML5 iframe sandbox attribute

Does anyone know how to detect if the iframe sandbox attribute is supported by the browser without relaying on version checks, etc?

like image 399
Pass Avatar asked Nov 15 '12 14:11

Pass


1 Answers

You can check whether an iframe element has the sandbox attribute:

var sandboxSupported = "sandbox" in document.createElement("iframe");

Side note

A good way to find feature detects is to look at Modernizr and see if it has one already. This is the Modernizr code for the sandbox attribute test:

Modernizr.addTest('sandbox', 'sandbox' in document.createElement('iframe'));

Alternatively (if you need to use lots of feature detects in your app) include Modernizr and use it properly, instead of just getting ideas from its source!

like image 89
James Allardice Avatar answered Oct 13 '22 00:10

James Allardice