#1
  1. Kage Bunshin
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2005
    Location
    The Seven Seas Of Rhye
    Posts
    930
    Rep Power
    422

    Firefox Refresh on Back


    I have a page with a form which uses a captcha. This all works great, except when the user clicks their backbutton in firefox. They get back to the form ok, but the old (used) captcha image is still there. For some reason, firefox doesn't refresh when the back button is pressed. I thought that if I used javascript to refresh the image that might solve the problem, but apparently firefox doesn't execute javascript when the back button is pressed either. I finally worked out a system where it changes the image when the submit button is clicked, but it doesn't work all the time. Can someone please help me refresh my captcha when the back button is pressed in firefox? Here is basically what my code boils down to:
    Code:
    <html>
    <head>
    <SCRIPT language="JavaScript" type="text/javascript">
        var img;
        var name;
        function preloader() {
            img = new Image();
            name = "CAPTCHA.php?rand=" + rand();
            img.src = name;
        }
        function refresh() {
            document.images["CAPTCHA"].src = name;
            preloader();
        }
        function rand() {
            var random = "" + Math.random();
            return random.replace(/\./, "")
        }
        function submitForm() {
            refresh();
            document.test.submit()
        }
        preloader();
    </SCRIPT>
    </head>
    <body>
        <a onClick="javascript:refresh()">
           <img width="120" height="40" name="CAPTCHA" src="CAPTCHA.php" alt="Click to refresh">
        </a>
        <br>
        <form name="test" method="post" action="test.php">
              <input type="button" onClick="javascript:submitForm()" value="Click Me">
        </form>
    </body>
    </html>
    Thanks
    Last edited by tagmanadvance; February 22nd, 2008 at 02:18 PM.
    "Java makes impossible things possible, but makes easy things difficult." - Somebody

IMN logo majestic logo threadwatch logo seochat tools logo