how to detect if user is at the last page of the history stack

Discussion in 'Javascript' started by |-|erc, Aug 22, 2005.

  1. |-|erc

    |-|erc Guest

    when a user clicks back to get to my site, I want it to run a javascript
    function.

    can you detect when the FORWARD button is greyed out?

    Herc
     
    |-|erc, Aug 22, 2005
    #1
    1. Advertisements

  2. |-|erc

    Randy Webb Guest

    |-|erc said the following on 8/21/2005 10:10 PM:
    No. It is none of your business where I came from or where I am going.

    Besides, what difference does it make?
     
    Randy Webb, Aug 22, 2005
    #2
    1. Advertisements

  3. |-|erc

    |-|erc Guest

    windows.history.length will tell me how many sites are in your queue, so
    you are wrong.

    FORM --- submit ---> PAGE 2 [click Back to edit]

    When you click back (from my own page again), the form data is still there
    and you can edit it. But the javascript variables are reset so I need to
    reinitialise them using data from the form.

    Herc
     
    |-|erc, Aug 22, 2005
    #3
  4. Seeing that some browsers cache the DOM and others do not, I doubt any
    general solution is even possible.
     
    John W. Kennedy, Aug 22, 2005
    #4
  5. |-|erc

    RobG Guest

    The reply was in regard to determining if the forward button is enabled
    or not. How does the history length tell you that?

    Or are you saying that it *is* your business where Randy came from?
    Are you using your back button or the browsers? If it's yours, then you
    can attempt to do what you like by posting data to the server but if
    it's the browser back button, then some browsers retain the values and
    others don't.
    Then (attempt) to do so onload and expect to fail some of the time.
     
    RobG, Aug 22, 2005
    #5
  6. |-|erc

    |-|erc Guest

    so there's nothing like windows.history.length
    but it tells you how far through the history you are?

    say I wanted to make my own fast forward and fast back buttons.
    go +10 or go -10 pages, but when you're near the ends, it changes to +2
    or -2 pages.

    That's impossible because you have no idea where in the history stack you
    are??

    Herc
     
    |-|erc, Aug 22, 2005
    #6
  7. |-|erc

    |-|erc Guest

    I'm saying

    "its none of you business where I came from or where I am going" is not
    true,

    because I can easily tell how many sites you've been to.
    What I'm asking for is whether some of those are ahead of me in the history.

    I get the default form values when I tried that... not onload but directly
    parsed, code not contained in a function body. Onload may make a
    difference.... just a pain its in my header file.

    Herc
     
    |-|erc, Aug 22, 2005
    #7
  8. |-|erc

    RobG Guest

    Try the following:

    <body onload="alert(document.formA.elementA.value);">
    <form name="formA">
    <input type="text" value="fred" name="elementA">
    </form>
    </body>

    In both IE and Firefox the following behaviour is observed:

    1. On initial load, get an alert with 'fred'.
    2. Change the value to 'sue', click reload or ctrl+R, get 'sue'.
    3. Navigate to another site, press browser 'back' button, get 'sue'.
    4. Click in address bar, press enter, get 'fred'.

    If you run the script after the form but before onload, you will get the
    default values, not the 'current' ones. It seems that the browsers are
    loading the page, then looking at the cache to replace form values, then
    running onload.
     
    RobG, Aug 22, 2005
    #8
  9. |-|erc

    |-|erc Guest

    Right, I thought that would be a longshot, its strange when the form has SUE
    right in front of you and the alert is giving you FRED! I'll just use
    onload like I should have.

    Herc
     
    |-|erc, Aug 22, 2005
    #9
  10. |-|erc

    RobG Guest

    it's 'window.history', there is no 's' on the end.
    RTFM. Pay particular attention to the statement "There is no public
    standard that applies to this object":

    <URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_history.asp>
     
    RobG, Aug 22, 2005
    #10
  11. |-|erc

    Randy Webb Guest

    |-|erc said the following on 8/21/2005 10:31 PM:
    That does not tell you:

    1) How many sites *before* your site.
    2) How many sites *after* your site.
    3) What and where I was.

    What's in my history trail is none of your business.

    But to solve your problem, onload of the page, check your variables and
    your forms and act accordingly. Then, forget about my history trail
    because it won't matter.
     
    Randy Webb, Aug 22, 2005
    #11
  12. |-|erc

    |-|erc Guest

    It tells you "how many sites are in your history trail" so your deduction is
    flawed.
    I can put up a page "BEEN TO 250 SITES TODAY ALREADY.... TIRED OF SURFING
    YET?"
    or "JUST STARTING ON THE COMPUTER TODAY... BEEN TO A HALF DOZEN SITES?"

    Herc
     
    |-|erc, Aug 23, 2005
    #12
  13. |-|erc

    Randy Webb Guest

    |-|erc said the following on 8/22/2005 7:49 PM:
    No, your interpretation of my deduction is flawed. It will NOT tell you
    where you are in the stack, only that you are in the stack and among X
    number of pages. The fact that you think that is any of your business
    also shows the fallacy in your thinking process.

    I bet that would go over well..... Even though it isn't true. The
    appropriate statement would be more like "According to your history
    trail, you have visited J number of sites since your cache/history were
    last cleared"/
    "Just started since clearing your history....."

    Try this test:

    Open the browser. In your case, use IE since it gives the history.length.

    Navigate 200 or so pages.
    Clear the history trail.
    Close the browser.
    Reopen the browser.
    Open your "infallibly stupid page" that tells how many sites you have
    been on.

    How many does it show?

    And then, explain if you have access to my history trail, why you can't
    tell me whether the back or forward buttons or greyed or not, because
    you can't. Its none of your business.
     
    Randy Webb, Aug 23, 2005
    #13
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.