Compaibility issue: window.location mismatch with browser locationbar

Discussion in 'Javascript' started by spam_me_ not, Jul 29, 2004.

  1. spam_me_ not

    spam_me_ not Guest

    I already understand that one cannot disable a browser's
    forward and back functions. This is a situation where I
    have code working in Mozilla V1.6 and would like something
    similar for Opera and IE.

    I link within a page and display individual divisions of
    that page, manipulating their visibility and display styles
    with an onClick function. As long as I explicitly click a
    link to progress, it works with browsers I've tried.

    If I click the browser's back button I see the content of
    the browser's location bar change as I expect. But I
    need to set the visibility and display styles for the
    corresponding division. In Netscape/Mozilla I have a little
    function enabled by setInterval(). It looks to see if
    window.location.hash matches the division which is visible
    and modifies styles accordingly.

    Under IE window.location.hash seems to be "stuck" at the
    most "forward" link. Under Opera I can get only the URL
    without the hash; it claims that the hash property is
    undefined or empty. I've tried document.location and
    document.URL with the same results.

    Since there's no page load or unload involved, there's no
    event generated; I could kludge some history of my own to
    traverse.

    Am I looking in the right place to get the hash info? Is
    there some direct access to read the location bar?

    Is there another approach to the problem, other than breaking
    up the page so that I force a load or unload?

    Thanks for any help.
     
    spam_me_ not, Jul 29, 2004
    #1
    1. Advertising

  2. spam_me_ not

    Randy Webb Guest

    Re: Compaibility issue: window.location mismatch with browser location

    spam_me_ not wrote:

    > I already understand that one cannot disable a browser's
    > forward and back functions. This is a situation where I
    > have code working in Mozilla V1.6 and would like something
    > similar for Opera and IE.
    >
    > I link within a page and display individual divisions of
    > that page, manipulating their visibility and display styles
    > with an onClick function. As long as I explicitly click a
    > link to progress, it works with browsers I've tried.
    >
    > If I click the browser's back button I see the content of
    > the browser's location bar change as I expect. But I
    > need to set the visibility and display styles for the
    > corresponding division. In Netscape/Mozilla I have a little
    > function enabled by setInterval(). It looks to see if
    > window.location.hash matches the division which is visible
    > and modifies styles accordingly.
    >
    > Under IE window.location.hash seems to be "stuck" at the
    > most "forward" link. Under Opera I can get only the URL
    > without the hash; it claims that the hash property is
    > undefined or empty. I've tried document.location and
    > document.URL with the same results.


    Read the document.location.href and then parse it yourself. You should
    know the current URL, simply remove that from the string and then read
    the rest.

    document.location.search might be an alternative, it would require you
    use the ? instead of the #
     
    Randy Webb, Jul 29, 2004
    #2
    1. Advertising

  3. spam_me_ not

    spam_me_ not Guest

    Re: Compaibility issue: window.location mismatch with browser location

    >> ...
    >> Under IE window.location.hash seems to be "stuck" at the
    >> most "forward" link. Under Opera I can get only the URL
    >> without the hash; it claims that the hash property is
    >> undefined or empty. I've tried document.location and
    >> document.URL with the same results.

    >
    > Read the document.location.href and then parse it yourself. You

    should > know the current URL, simply remove that from the string and
    then read > the rest.
    >
    > document.location.search might be an alternative, it would require

    you > use the ? instead of the #

    Thanks for the thoughts. But document.location.href shows the
    same situation as document.location.hash and parsing it myself
    would make no difference. (In fact, for debugging I displayed
    ..href so I could be sure of what was going on.)

    I tried passing the information in document.location.search.
    That causes other behaviors in IE and Opera but I still get
    the same basic problems I had before.

    I decided on a different approach. If the navigation history
    within the page is actually useless since the navigation bar
    is always available, then window.location.replace() will
    avoid a history. The back button goes to my page's referrer,
    and forward would go to some other page. That also allows me
    to get rid of the setInterval() and the routine it invokes.

    Again, it works in Mozilla/Netscape, but not in IE and Opera.
    IE *keeps* the history, and the browser's back function leaves
    the wrong section visible. Opera does the right thing with
    the history but insists on forcing visibility and display
    for the division I'm leaving. I have an alert() immediately
    after the assignment into window.location so I can see the
    *correct* division displayed while the alert() is active. I
    then see it revert to the division I'm leaving once I dismiss
    the alert().

    Here's a code snippet that shows the basic setup:

    var idList = new Array("sched", "lead", "cont");

    function swapVisibility(theId) {
    document.location.replace("veeblefetzer.html#" + theId);
    var hideIt;
    for (var i=0; i<idList.length; i++) {
    hideIt = document.getElementById(idList);
    hideIt.style.visibility = "hidden";
    hideIt.style.display = "none";
    }
    var becomeVisible = document.getElementById(theId);
    becomeVisible.style.visibility = "visible";
    becomeVisible.style.display = "block";
    alert(document.location.href+"\n"+theId);
    return true;
    } // end function swapVisibility

    <a onclick="swapVisibility('sched');" href="#sched">...</a>
    <a onclick="swapVisibility('lead');" href="#lead">...</a>
    <a onclick="swapVisibility('cont');" href="#cont">...</a>

    <div id="sched">
    ...
    </div>
    <div id="lead">
    ...
    </div>
    <div id="cont">
    ...
    </div>

    etc.

    Am I using document.location.replace() correctly?
     
    spam_me_ not, Jul 29, 2004
    #3
  4. spam_me_ not

    Richie Guest

    I think I can describe the solution to the problem as
    breaking out of a Netscape V4 mindset. Instead of
    changing visibility as part of an anchor tag, I use
    the onClick within a paragraph tag. That immediately
    gets rid of the navigation history in all browsers.
    document.location.replace() is gone.

    There's an option to view all sections at once. If
    that's enabled, I shove the target location (hash)
    into document.location. That gets back into the
    navigation history again, but that's acceptable in
    what is now a longish page.

    The browser incompatibilities, well, chalk 'em up to
    something else to remember for future work. This
    approach is much cleaner, not just a "workaround."
     
    Richie, Jul 30, 2004
    #4
  5. spam_me_ not

    Grant Wagner Guest

    Re: Compaibility issue: window.location mismatch with browserlocationbar

    Richie wrote:

    > I think I can describe the solution to the problem as
    > breaking out of a Netscape V4 mindset. Instead of
    > changing visibility as part of an anchor tag, I use
    > the onClick within a paragraph tag. That immediately
    > gets rid of the navigation history in all browsers.
    > document.location.replace() is gone.


    location is a property of the default window object, so it's
    window.location.replace(). document.location is deprecated, has
    been for a long time.

    <url:
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/document.html
    />
    "Do not use location as a property of the document object; use
    the document.URL property instead. The document.location
    property, which is a synonym for document.URL, is deprecated."

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Jul 30, 2004
    #5
  6. spam_me_ not

    Richie Guest

    Re: Compaibility issue: window.location mismatch with browser locationbar

    Grant Wagner wrote:
    > Richie wrote:
    >
    >
    >>I think I can describe the solution to the problem as
    >>breaking out of a Netscape V4 mindset. Instead of
    >>changing visibility as part of an anchor tag, I use
    >>the onClick within a paragraph tag. That immediately
    >>gets rid of the navigation history in all browsers.
    >>document.location.replace() is gone.

    >
    >
    > location is a property of the default window object, so it's
    > window.location.replace(). document.location is deprecated, has
    > been for a long time.
    >
    > <url:
    > http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/document.html
    > />
    > "Do not use location as a property of the document object; use
    > the document.URL property instead. The document.location
    > property, which is a synonym for document.URL, is deprecated."
    >
    > --
    > Grant Wagner <>
    > comp.lang.javascript FAQ - http://jibbering.com/faq
    >


    I tried all three variations along the way. Apologies for
    using the deprecated property in my description.
     
    Richie, Aug 3, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    99
    Thomas 'PointedEars' Lahn
    Nov 14, 2003
  2. ZER0

    Locationbar Object

    ZER0, Jul 7, 2004, in forum: Javascript
    Replies:
    3
    Views:
    80
    Javier Casabella
    Jul 7, 2004
  3. saiho.yuen
    Replies:
    3
    Views:
    437
    kaeli
    Sep 14, 2004
  4. Ari Krupnik
    Replies:
    0
    Views:
    222
    Ari Krupnik
    Dec 3, 2006
  5. Alex Bird
    Replies:
    3
    Views:
    189
    Thomas 'PointedEars' Lahn
    May 9, 2008
Loading...

Share This Page