soon_j has asked for the wisdom of the Perl Monks concerning the following question:

Monks! Good morning (at least from my place). I need enlightenment on how to clear my browser's history from within my perl script.

I can't see a Javascript method either that clears the history.

When someone clicks a link in my page, I simple wouldn't want them to click the "back" button of the browser nor move back in time.

Do you have any ideas? Thanks.

Replies are listed 'Best First'.
Re: How to Clear Browser History
by iburrell (Chaplain) on Jun 15, 2004 at 22:35 UTC
    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.

      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.

Re: How to Clear Browser History
by peschkaj (Pilgrim) on Jun 16, 2004 at 02:17 UTC

    This may sound foolish, but if you are writing an online exam, you might want to take a look at using Flash.

    Another thing you could do is store the information in a cookie (encrypted?) and store similar data somewhere on the server for verification (a lot of bandwidth, I know). In a web application I recently worked on, I store the next page as a session variable. However, this application isn't an exam.

    One thing you could do is maintain an array, or comma separated list, in session to determine which questions have been answered. If the user goes back and tries to change an answer, let them think that they've changed their answer, but check to see if this is a resubmit, if so, trash their response and move to the proper page.



    If you make something idiot-proof, eventually someone will make a better idiot.
    I am that better idiot.
Re: How to Clear Browser History
by BrowserUk (Patriarch) on Jun 15, 2004 at 22:18 UTC

    Just say no!


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
Re: How to Clear Browser History
by borisz (Canon) on Jun 15, 2004 at 22:23 UTC
    Open a new window. Then you have no browser history.
    Boris
      I would end up with sooooo many windows if I do that.
Re: How to Clear Browser History
by dba (Monk) on Jun 16, 2004 at 17:31 UTC
    check this:
    http://developer.irt.org/script/311.htm