Вопрос

I have a captcha image for form validation and a javascript to refresh the image if it is unreadable for the user. The script works fine in Chrome, but in Firefox it only works the first time and, after that, though the script runs, the image does not refresh. the image src includes:

<?php echo "?rand=" . rand(); ?>

But despite the fact that the php is working just fine, the refresh is still inoperable.

I've checked this, and this, and have tried many of the suggestions - for example adding and removing no cache meta tags, changing the body and head tags to h:body and h:head.

Many of the suggestions (eg the one here) describe code situations different from mine (in my case I am using a php-generated image.

Any help will be very appreciated.

        <script type="text/javascript">
        function refresh_captcha()
        {
            var img = document.getElementById('captchaimg');
            img.src = 'captcha_code_file.php?rand=<?php echo(rand()); ?>';
            document.getElementById ("captchaimg").src = img.src;
            //alert("some alert.");

        }

The page is here

Это было полезно?

Решение

Try to use this, random not php, but JS.

function refresh_captcha()
    {
        var img = document.getElementById('captchaimg');
        img.src = 'captcha_code_file.php?rand=' + Math.random();
        document.getElementById ("captchaimg").src = img.src;
        //alert("some alert.");
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top