Reload previous page on "back" button.

Posted on 2007-10-03
Last Modified: 2013-11-19
Hello JS gurus.

Do you know if there's any way, using JavaScript, to ensure that when the back button is pressed, the previous page (history.go(-1)) is *reloaded* for *all users*, rather than just loaded from the cache?

I thought it might be possible to put JavaScript into the page that would reload it if it was reached by pressing the back button, but I have no idea how to detect if this is the case.

Any help would be most appreciated.

Question by:ratWonder
    LVL 75

    Expert Comment

    by:Michel Plungjan
    You should fix your application so it can handle a back or not depend on handling a back

    You can expire the page and use POST for one
    LVL 4

    Author Comment

    Sorry I didn't understand that.

    I tried preventing the browser from caching by adding:
      <meta http-equiv="Pragma" content="no-cache" />
      <meta http-equiv="Expires" content="-1" />

    But no joy - when I click back it still shows the old version of the page.
    LVL 75

    Accepted Solution

    1. you cannot safely detect a back button
    2. In page1 you can reload if a cookie is set from page2 (and delete the  cookie), and set a cookie on page2
    3. if you have a form and you change the method to POST the page will complain if you use the back button
    4. you can remove the page completely from the history by
    <a href="page2.html" onClick="location.replace(this.href); return false">Go to page 2 and never return to page1</a>
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    Zoom web page in 2 21
    CRM 2011 Error when closing 17 29
    HTML5 and Javascript 3 21
    Button not taking me to the href 3 13
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now