typeof 返回“未知"在浏览器中 [英] typeof returning "unknown" in IE

查看:20
本文介绍了typeof 返回“未知"在浏览器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口,在关闭之前我会刷新底层页面.

I have a window, where before being closed I refresh the underlying page.

if(opener && typeof(opener.Refresh) != 'undefined')
{
    opener.Refresh();
}

如果我离开原来的打开页面,这段代码会抛出一个权限被拒绝"错误.

If I moved away from the original opening page, this code would throw a "Permission Denied" error.

调试代码后发现 typeof(opener.Refresh) 等于 "unknown" 而不是预期的 "undefined".

Debugging the code revealed that typeof(opener.Refresh) was equal to "unknown" instead of the expected "undefined".

据我所知 "unknown" 不是 typeof 的返回值之一,那么如何以及为什么会返回该值?

As far as I'm aware "unknown" is not one of the return values for typeof, so how and why would this value be returned?

更多信息

我通过将检查更改为:

if(opener && typeof(opener.Refresh) == 'function')

但是这样的例子(detecting-an-undefined-object-property-in-javascript) 似乎没有将未知"因素考虑在内.

However examples like this (detecting-an-undefined-object-property-in-javascript) do not seem to factor "unknown" into the equation.

推荐答案

根据 Bytes 的重复问题,值类型 unknowndate 一起添加到 JScript 版本 8.

According to a duplicate question at Bytes, the typeof value unknown is added to JScript version 8, along with date.

对 Robert Nyman 博客的评论也可以解释一下:

A comment to a blog by Robert Nyman can also be explanatory:

当有问题的对象打开时,Internet Explorer 显示未知"COM+ 桥的另一侧.你可能不知道或意识到但是 MS 的 XMLHTTP 对象是不同 COM+ 对象的一部分实现 IUnknown;当你调用它的方法时,你就结束了一个 COM 桥,而不是调用原生 JavaScript.

Internet Explorer displays "unknown" when the object in question is on the other side of a COM+ bridge. You may not know this or realize this, but MS’s XMLHTTP object is part of a different COM+ object that implements IUnknown; when you call methods on it, you’re doing so over a COM bridge and not calling native JavaScript.

如果您尝试测试或访问某些东西,基本上这就是 MS 的答案这不是 JScript 引擎的真正组成部分.

Basically that’s MS’s answer if you try to test or access something that’s not a true part of the JScript engine.

这篇关于typeof 返回“未知"在浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆