gpt4 book ai didi

Javascript .pathname IE 怪癖?

转载 作者:IT王子 更新时间:2023-10-29 03:19:09 29 4
gpt4 key购买 nike

考虑以下 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”的内容(注意前面的正斜杠)。

这里是 IE 的问题,怎么回事?

最佳答案

W3C standard on the window object - 包括位置界面 - 日期为 2006 年 4 月 7 日,即它是在实际实现多年后指定的。

标准如下:

pathname

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's implementation 一致.

MSDN doc on the location object没有提到该属性包含什么,而是一个 page on the VBScript location object有一个与你的发现一致的例子。

正如所说的页面是 ©1996 - W3C 介入的十年前 - 说 IE 有错是不公平的,但我仍然认为它是一个错误。

关于Javascript .pathname IE 怪癖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/956233/

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