Reload recaptcha on browser back button

2019-08-05 11:05发布

I have tried numerous methods to reload the image when paging back but no matter what i try i get the same image. Some methods were close ( i can see the image refresh, but the recaptcha server responds back and the previous image reappears). Is there some trick to getting the image to reload when clicking the back button? I dont want my users to have to re-enter all the form information if they type the security words incorrectly. I also want to avoid storing all the information. The page is classic asp, so jquery or ajax methods would be the route to go, or so id assume. Thanks in advance.

5条回答
爷、活的狠高调
2楼-- · 2019-08-05 11:23

I managed to get it to refresh correctly by using this line of code:

body onLoad="javascript:Recaptcha.reload()"

But this method is not a good solution because the focus sets on the recaptacha text field, which means the window scrolls down to the bottom of the page which is where the recaptacha field is, even when you enter the page for the first time (not only when pressing "BACK" to the page). This solution works but it would be better to find a solution which does not set the focus on the recaptacha input field.

查看更多
爷的心禁止访问
3楼-- · 2019-08-05 11:33

I figured out a quick hack that fixes this issue. On the page with the recaptcha add the following jquery

<script>
$(document).ready(function(){
  $("#form_div").Show();
);
</script>

Just replace "#form_div" with whatever div houses your form. Now when the user hits the back button it refreshes the recaptcha image. It is a hack in every sense of the word, but it worked for me.

查看更多
神经病院院长
4楼-- · 2019-08-05 11:37

This is the easy method that works with Chrome:

Add reload function on HTML body as below:

<body onload="javascript:Recaptcha.reload()">

And reCaptcha image auto reloads in Chrome when user click the back button.

查看更多
Fickle 薄情
5楼-- · 2019-08-05 11:39

Call your refresh method from window.onload:

window.onload = function(){ /* refresh here */ }
查看更多
老娘就宠你
6楼-- · 2019-08-05 11:44

Edit: removed history API answer to show possible AJAX answer.

With jQuery it is ridiculously easy.

$(window).on('load',function(){
    $('#RecaptchaContainer').load('/path/to/recaptcha.php',function(){
         // any javascript you need to perform on the recaptcha
    });
});

You can have all the recaptcha HTML in that file, but you can contain all the javascript within that callback function.

查看更多
登录 后发表回答