js功能检测

怎么检测浏览器是否支持某一功能?

 1 function isLocalStorageSupported() {
 2     var testKey = 'test',
 3         storage = window.sessionStorage;
 4     try {
 5         storage.setItem(testKey, 'testValue');
 6         storage.removeItem(testKey);
 7         return true;
 8     } catch (error) {
 9         return false;
10     }
11 }

看到这段代码,挺不错的。

原文地址:https://www.cnblogs.com/newh5/p/7419510.html