Does anyone know how to detect if the iframe sandbox attribute is supported by the browser without relaying on version checks, etc?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With