gpt4 book ai didi

javascript - 对象不支持此属性或方法。为什么?

转载 作者:行者123 更新时间:2023-11-30 18:30:14 26 4
gpt4 key购买 nike

如果我在 IE8 或更低版本上运行此代码,我会收到此错误:Object doesn't support this property or method

var hasFlash = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));

最佳答案

可能 new ActiveXObject 部分失败了,因为 ActiveXObject (在您当前的设置中)不是可以应用 new 运算符的任何东西到——或“ShockwaveFlash.ShockwaveFlash”不是有效输入,因此抛出异常。

不过,您可以轻松地重写代码来解决该问题:

var hasFlash = (function() {
if (typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") {
return true;
} else if (typeof window.ActiveXObject != "undefined") {
try {
new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
return true;
} catch (e) { }
}

return false;
})();

关于javascript - 对象不支持此属性或方法。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9856832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com