【发布时间】:2012-11-04 03:57:04
【问题描述】:
有谁知道如何检测浏览器是否支持 iframe 沙盒属性而不中继版本检查等?
【问题讨论】:
标签: javascript html google-chrome iframe sandbox
有谁知道如何检测浏览器是否支持 iframe 沙盒属性而不中继版本检查等?
【问题讨论】:
标签: javascript html google-chrome iframe sandbox
您可以检查iframe 元素是否具有sandbox 属性:
var sandboxSupported = "sandbox" in document.createElement("iframe");
旁注
查找特征检测的一个好方法是查看Modernizr,看看它是否已经有了。这是Modernizr code for the sandbox attribute test:
Modernizr.addTest('sandbox', 'sandbox' in document.createElement('iframe'));
或者(如果您需要在您的应用中使用大量功能检测)包括 Modernizr 并正确使用它,而不是仅仅从源头获取想法!
【讨论】: