开发者

Chrome treats document.location.href differently?

on the following URL: www.example.com/page/#2221

  • Chrome will return www.example.com/page/# for document.location.href
  • Firefox will return www.example.com/page/#2221 for document.location.href

Is there another alternative to have them both return www.example.com/page/#222开发者_Go百科1?


What about something like this?

function getUrl() {
  var location = document.location.href,
      locationLength = location.length,
      hash = document.location.hash;

    if (hash 
        && location.substring(locationLength - 1, locationLength) == '#') {
        location += hash;
    }

    return location;
}

jsFiddle.

They return the same thing in Firefox 3.6.13 and Chrome 9.

Though I've always used window.location.


document.location is deprecated. Try using window.location.href instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜