Use location.hash (with or without '#')

Y

Yimin Rong

The reference I have says that hash is a read/write string that
specifies the anchor portion of the current URL, including the leading
"#". So, for example:

location.hash = "#intro";

Would move to the "intro" section of the current document. I've found
that the above code doesn't work in some browsers, in particular
Netscape 4.X for Windows, and almost all IE & Netscape for Macintosh
OS9 and OSX.

I looked around and the 'correct' code to use for many of those
browsers seems to exclude the leading "#":

location.hash = "intro";

Some questions:

Is there a way to find out in client-side JavaScript which convention
a browser/OS combination uses? (Preferably something that doesn't use
the user agent string.)

If not, if I omit the leading "#" as a default, will it run into
problems with the newer browsers? (If I had to choose, my choice is to
move forward with the new compliant browsers.)

Thanks for reading,

Yimin Rong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top