Javascript .pathname IE quirk? [英] Javascript .pathname IE quirk?

查看:127
本文介绍了Javascript .pathname IE quirk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下Javascript:

Consider the following Javascript:

var anchors = document.getElementsByTagName('a');
for(var i=0; i < anchors.length; i++)
{
    alert(a.pathname);
}

当我在包含格式为 http://foo.com/bar ,在IE8中我收到一个看起来像bar的字符串。在Safari,Chrome,Firefox中,我得到类似/ bar的内容(请注意前导斜线)。

When I run this on a page that contains links in the format "http://foo.com/bar", in IE8 I get back a string that looks like "bar". In Safari, Chrome, Firefox, I get back something like "/bar" (note the leading forward slash).

IE在这里有问题,这是什么交易?

Is IE at fault here, what's the deal?

推荐答案

窗口对象上的W3C标准 - 包括位置界面 - 日期为2006年4月7日,即在实际实施已经存在多年后指定。

The W3C standard on the window object - including the location interface - is dated 07 April 2006, ie it was specified after actual implementations had been around for years.

标准显示:


路径名

此属性表示Location的URI的路径组件,它包含主机和端口之后的所有内容,包括第一个问号(?)或井号(#)。

This attribute represents the path component of the Location's URI which consists of everything after the host and port up to and excluding the first question mark (?) or hash mark (#).

这意味着应该包含前导斜杠,这与 Mozilla的实现n

This means the leading slash should be included, which is consistent with Mozilla's implementation.

位置对象上的MSDN doc 没有提到该属性包含的内容,而是 VBScript位置对象上的页面有一个与您的发现一致的示例。

The MSDN doc on the location object doesn't mention what the property contains, but a page on the VBScript location object has an example consistent with your discovery.

正如所述页面是©1996 - 在W3C参与之前十年 - 说IE出错是不公平的,但我仍然认为这是一个错误。

As said page is ©1996 - ten years before the W3C got involved - it's hardly fair to say that IE is at fault, but I'd still consider it a bug.

这篇关于Javascript .pathname IE quirk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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