如何区分 JS 提交和使用后退按钮(onbeforeunload)?
我对 onbeforeunload 和 form.submit() 感到疯狂。你是我对绝妙想法的最后希望……
我所拥有的只是一个形式。如果用户单击后退按钮,这会造成很多麻烦,因此 window.onbeforeunload 会显示警告。当然应该允许提交表单,因此 form.onsubmit 设置一个全局变量来告诉 onbeforeunload 函数关闭。到目前为止还好。
有时必须通过 JS 自动提交表单。而且我无权访问调用 form.submit() 的函数 - 或者更准确地说 - 用户将创建一些可能包含 form.submit() 的简单代码。
要点是,根据规范,form.submit() 不会触发表单的 onsubmit 事件。因此,尝试通过 form.submit() 发送表单会定期告诉我考虑关闭页面。
回到我的希望:有人有一个绝妙的主意如何解决这个恶性循环吗?
多谢 伯宁利奥
I am going crazy with the onbeforeunload and form.submit(). You are my last hope for a brilliant idea...
What I have is a form. If the user clicks the back button, this causes a lot of trouble, so window.onbeforeunload shows a warning. Of couse submitting the form shall be allowed, therefore form.onsubmit sets a global variable to tell the onbeforeunload-function to shut up. So far allright.
Sometimes the form must be submitted automatically via JS. And I do not have access to the functions that call the form.submit() - or more exactly - users will create some simple code that may include a form.submit().
The point is that form.submit() does, by specification, not trigger the form's onsubmit event. Therefore trying to send a form via form.submit() regularly tells me to consider closing the page.
So back to my hope: Does anyone have a brilliant idea how to solve this vicious circle?
Thanks a lot
BurninLeo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)