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 }

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

posted @ 2017-08-23 18:08  不由分说  阅读(144)  评论(0编辑  收藏  举报