如何检测给定浏览器是否具有 URL
的 searchParams
原型(prototype)? https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams声明 Chrome 和 FF 有但 Edge 没有,但我希望使用 JavaScript 进行检测。
我已经弄乱了 isPrototypeOf
,但认为它不适用。
最佳答案
在支持的浏览器中,会有一个URLSearchParams
全局对象上可用的构造函数,因此与任何其他全局构造函数一样,
'URLSearchParams' in window
或
typeof window.URLSearchParams === 'function'
类似的都可以。
const support = typeof window.URLSearchParams === 'function';
console.log('supports URLSearchParams API:', support);
var url = new URL('https://stackoverflow.com/questions/47824782/how-to-tell-if-an-object-has-a-given-prototype?support="true"');
if(support){
console.log(url.searchParams.get('support'));
}
关于javascript - 如何判断一个对象是否具有给定的原型(prototype)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47824782/