返回的“未知”类型在IE中 [英] typeof returning "unknown" in IE

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

问题描述

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

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

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

如果我离开原始的开始页面,这段代码会抛出一个Permission Denied错误。

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?

更多信息

Further Information

我避免了将支票更改为以下错误:

I avoided the error by changing the check to:

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

然而这样的例子( detect-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.

推荐答案

根据字节重复的问题,类型值 unknown 被添加到JScript版本8,以及 date

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

A 评论也可以解释为:


当对象显示未知时,Internet Explorer有问题的是COM +桥的另一边
。你可能不知道这个或实现
这个,但MS的XMLHTTP对象是
实现IUnknown的不同COM +对象的一部分;当你在它上面调用方法时,你这样做就超过了
a 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.

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

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