in reply to How to Clear Browser History

You can't clear the user's browser history from a Perl script on the web server. There is no way in JavaScript to clear the history. I have seen a technique where JavaScript is used to replace the page, overwriting the entry in the history.

I would ask why you want to control this. It can't be for privacy; they have already seen the page. It shouldn't be for protecting the control flow. They can find other ways to screw it up than going back in the history. For one thing, people can open links in new windows or tabs and see both the current and previous pages simultaneously.

Replies are listed 'Best First'.
Re^2: How to Clear Browser History
by soon_j (Scribe) on Jun 15, 2004 at 22:44 UTC

    I am using it for an exam that displays only one question at a time on a page. As the user moves on from one question to the next, I don't wan't him to go back and re-answer an already answered question.

    Though my scripts has several sanity checks that prevent internally from within my script the same question to be re-answered, I just needed some way to clear the history as an immediate but temporary fix to a flaw that I noticed in my design.

    The flaw is, take for example you are in question number 2. I have navigation buttons on my page that allows me to move to the next, previous, first, or last item in the exam whose dynamic values are stored in a session. Now if a user goes back (through his browser) to re-answer question 1, when he clicks the next button, since in my session the next button points to Ques no 3, it would simply interpret the submission as an answer for Ques no 2 and not what the user thinks (that he's re-answering Ques No 1).

      Add a hidden field to the page with a key for the question being answered. You can check against this on the server. If it's not present or if it doesn't match the question you think someone's answering, do whatever's appropriate.