Closed Bug 277456 Opened 20 years ago Closed 20 years ago

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

Categories

(Core :: DOM: Core & HTML, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 483304

People

(Reporter: spam_from_bugzilla, Unassigned)

Details

Attachments

(1 file)

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.
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
Closed: 20 years ago
Resolution: --- → WONTFIX
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
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: