简体   繁体   English

使用AJAX提交表单时,选项卡上的Safari Popup关闭

[英]Safari Popup on tab close when submitting forms with AJAX

In Safari Browser, on a page with a form, there is a system modal popup that opens when the user tries to close the browser's tab and the form hasn't been validated. 在Safari浏览器中,带有表单的页面上有一个系统模式弹出窗口,当用户尝试关闭浏览器的选项卡并且尚未验证表单时,该窗口会打开。 Text says: You have entered text on “[name of the page]”. 文字说: 您已经在“ [页面名称]”上输入了文字。 If you close the window, your changes will be lost. 如果关闭窗口,所做的更改将丢失。 Do you want to close the window anyway? 您是否仍要关闭窗口?

This behavior is ok when the post redirects to another the page. 当帖子重定向到另一个页面时,此行为是可以的。 On our site, we have a page that validates a form using an Ajax Request. 在我们的网站上,我们有一个页面,该页面使用Ajax请求来验证表单。 As the page is not reloaded, even if the form has been submitted, the popup appears, and it might feel strange for the end user. 由于未重新加载页面,因此即使提交了表单,也会显示弹出窗口,并且对于最终用户可能会感到很奇怪。

The post is triggered by a button: 该帖子由一个按钮触发:

  1. Forms are validated using the jQuery Validation plugin 使用jQuery Validation插件验证表单
  2. Plugin options include a submitHandler option that return false; 插件选项包括一个return false;submitHandler选项return false;
  3. Date are sent via $.post , and a message informs user for success/failure. 日期通过$.post发送,并且一条消息通知用户成功/失败。

Does anyone have an idea about how to avoid this popup to be triggered once the call returns? 有谁知道如何避免一旦呼叫返回就触发此弹出窗口? We'd wish not to force a reload in that case. 在这种情况下,我们不希望强制重新加载。

Note that this behavior can be changed by the user , but not very easily... 请注意,此行为可由用户更改 ,但不是很容易...

I can't replicate this in Safari on Windows. 我无法在Windows的Safari中复制它。

Maybe try emptying/resetting the input fields once the form has been submitted, only if there weren't any errors with the submission of course, or better yet, remove the form completely, if it's not needed after. 提交表单后,也许可以尝试清空/重置输入字段,当然前提是提交过程中没有任何错误,或者更好的是,完全删除表单,如果以后不需要的话。 Of course using DOM manipulation, not by reloading the page. 当然使用DOM操作,而不是通过重新加载页面。

On a side note, seeing the filled-out form after it's been sent (even if you're showing a confirmation message) also can be strange for the user (unless it's a multiple-use form and this behaviour is expected). 附带说明一下,发送后看到填写好的表单(即使您正在显示确认消息)对于用户来说也很奇怪(除非它是多次使用的表单,并且这种行为是可预期的)。

UPDATE: tested on a Mac Safari, it's behaving as you described, but if I remove what I typed (that made the browser alert me in the first place), it doesn't come up. 更新:在Mac Safari上进行了测试,它的行为符合您的描述,但是如果我删除键入的内容(首先使浏览器提醒我),它就不会出现。 So, simple reset of the fields should do the trick. 因此,只需重置字段即可解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM