document.location.hash is URI-decoded, .href isn't

RESOLVED DUPLICATE of bug 483304

Status

()

Core
DOM
RESOLVED DUPLICATE of bug 483304
14 years ago
9 years ago

People

(Reporter: Phil Endecott, Unassigned)

Tracking

Trunk
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

14 years ago
If I visit foo.html#abc%20def, should the %20 be decoded to a space when I read
from document.location?  It seems that if I read from document.location.href I
see the %20, while reading from document.location.hash I see a space.  Internet
Explorer always returns %20.

As far as I can see this is not defined by any of the DOM specifications yet.  I
think I would prefer to get %20 in .hash since that is consistent with both the
other browser and .href.  Any thoughts?

I will attach a simple demo.

Appologies if this is already known.  This is with Firefox 1.0.
(Reporter)

Comment 1

14 years ago
Created attachment 170581 [details]
Prints out .href and .hash
See discussion in bug 135309.  In short, IE sometimes unescapes and sometimes
doesn't, which means that for identical URIs it can show different location.hash
values.  We always unescape.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → WONTFIX
(Reporter)

Comment 3

14 years ago
Boris - sorry, can't think how I failed to find that bug.  Must improve
Bugzilla-searching skills.

For the benefit of anyone who has the same problem: in summary, don't use
location.hash in multi-browser code.  I use this:

function document_location_hash() {
  var hr=document.location.href;
  var p=hr.indexOf('#');
  if (p>=0) {
    return hr.substr(p+1);
  } else {
    return "";
  }
}
Resolution: WONTFIX → DUPLICATE
Duplicate of bug: 483304
You need to log in before you can comment on or make changes to this bug.