单击按钮刷新页面时,window.onbeforeunload不起作用 [英] window.onbeforeunload shouldnt work when refresh the page with clicked button

查看:705
本文介绍了单击按钮刷新页面时,window.onbeforeunload不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个注册表格.所以我想当用户不小心刷新或关闭选项卡或浏览器并且访问者在某人中写了东西

I have a sign up form in my page. So I want when the user accidentally refresh or close tab or browser and the visitor has written something in someone

<input type="text" placeholder="something"/>

然后出现:

return "you have to fill the whole form";

一切正常,但是按钮有问题! 该按钮没有 JavaScript jQuery 功能. 我的PHP脚本检查所有这些输入并刷新页面. 访问者填写整个表单,然后单击注册"并出现.

Everything works, but I have a problem with the button! The button has no Javascript and no jQuery function. My PHP-script checks all these inputs and refresh the page. The visitor fill the whole form and click signup and appear.

return "you have to fill the whole form";

这不应该是这样的,由于网页的安全性,我不能共享PHP代码.

This shouldn't be like this and I cannot share the PHP code because of the security of the webpage.

也许我可以用正确的JS或jQuery代码来解决这个问题!

Maybe can I fix this with the right JS or jQuery code!

jsFiddle演示: http://jsfiddle.net/dV9sU/9/

PS:对不起,我的英语.

PS: Sorry for my English.

推荐答案

此处: http://jsfiddle.net/dV9sU/11/

<input type="submit" name="sign_in" value="Registrieren" class="success_button" onclick="alert(onbeforeunload());" />

这篇关于单击按钮刷新页面时,window.onbeforeunload不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆