Detecting if the back button was used

Posted on 2006-04-21
Last Modified: 2012-05-05
I need to be able to detect in IE if the back button was used.  I am currently using javascript with perl as the backend.  I need to do this because my form is javascript created and creates a mess when the back button is used.  I would optimatly like to be able to refresh the form when the back button is used.

Thanks for all your help, the anser to this question seems to have been answered before but I am hoping that there is a more updated answer.  This is also an urgent matter

Question by:ralphsauto
    LVL 11

    Assisted Solution

    Hi Ralph,

    Try using the referrer property.  See this:

    Check if the referrer to your form page contains the url of your results page.  If it does, then you came from 'the wrong direction' and need to refresh the form.

    I hope this makes sense.

    Peace and joy.  mvan
    LVL 41

    Accepted Solution

    Unfortunately, I don't think that this will work.

    According to the "World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1":

    Source URL =

    referrer of type DOMString, readonly
                   Returns the URI of the page that linked to this page. The
                   value is an empty string if the user navigated to the page
                   directly (not through a link, but, for example, via a

    A slightly more detailed explaination can be found at
    This property returns a value only when the user reaches the
    current page through a link from the previous page.
    Otherwise, document.referrer returns an empty string;
    it also returns an empty string when the link is from a secure site.

    For example, if PageA.htm includes a link to PageB.htm, and
    the user clicks that link, the document.referrer on PageB.htm
    returns "PageA.htm". However, if the user is on PageA.htm
    and types PageB.htm into the address line or uses Open in
    the File menu to get to PageB.htm, the document.referrer
    returns an empty string.
      I think that the important part is the last part of the first

      In the tests that I did, I couldn't get referrer to have a value
    as long as the reference was from "the same site."  I presume
    that this is because the referrence was considered to be from
    "a secure site."

      You might need to save the "current page" in a session cookie,
    and check this value when your page is loaded.  If the "previous
    page" (i.e., the value of "current page" cookie) is inappropriate,
    then the form would need to be reloaded.

    Author Comment

    I am still trying to work this out so if there was a way to keep this, so that I can review it more later.  I agree HonorGod should get the points, and no one else has seen fit to make any replies.
    LVL 11

    Expert Comment

    ... indeed, I was tacitly agreeing with HonorGod.  Peace and joy.  mvan

    Author Comment

    I will close the question and split the points between the two people who answered the question, they did answer the question in good faith, even if the answer is one I did not want to hear.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One JavaScript Help from Top Experts

    Solve your toughest problems, fast.
    JavaScript experts are online now and ready to help you.

    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now