"#" prefix for location.hash?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yimin Rong

    "#" prefix for location.hash?

    Does anyone know if there are any browsers where you must specify "#"
    as a prefix when setting the hash for the location?

    For example, the following would move to the intro section of the
    document:

    window.location .hash = "#intro";

    But in the same browser, this would not work:

    window.location .hash = "intro";

    So far, in the browsers I've tested, the "#" seems to be optional. If
    this behaviour is compliant, any references, on-line or otherwise,
    would be welcome.

    Thanks,

    Yimin Rong
  • Stuart Palmer

    #2
    Re: "#&quot ; prefix for location.hash?

    I don't think this is a JS question as you can do hash anchors in html href
    code.

    I think you will find that if you put a <a name="#hashname "></a> in IE it
    will work and in netscape it won't (new versions of NS might work).
    IE is more intelligent than netscape so works out bad code and does work.

    The answer is, in the <a name="anchornam e"></a>, miss out the hash (#) and
    this will work in all browsers. Only on the link that goes to that
    page/section of the page do you put the hash symbol.

    <a href="page.html #intro">link</a>

    <a name="intro"></a> Your intro text.

    This will work in all browsers.
    Hope that helps.

    Stu

    "Yimin Rong" <yiminrong@yaho o.ca> wrote in message
    news:afc55314.0 308221147.3d32f e08@posting.goo gle.com...[color=blue]
    > Does anyone know if there are any browsers where you must specify "#"
    > as a prefix when setting the hash for the location?
    >
    > For example, the following would move to the intro section of the
    > document:
    >
    > window.location .hash = "#intro";
    >
    > But in the same browser, this would not work:
    >
    > window.location .hash = "intro";
    >
    > So far, in the browsers I've tested, the "#" seems to be optional. If
    > this behaviour is compliant, any references, on-line or otherwise,
    > would be welcome.
    >
    > Thanks,
    >
    > Yimin Rong[/color]


    Comment

    Working...