jQuery的:控制页面重载或从当前页面搬走 [英] jQuery: Control page reloads or moving away from the current page
问题描述
如果用户通过使用鼠标(点击链接)或键盘(按回车键,同时有一个表单元素集中)的互动,我想这样做能够运行JavaScript / jQuery的预先命令。<移动从当前页面离开/ p>
示范性的工作流程:
- 用户点击任何链接或点击一个按键,这将导致在浏览器中加载新页
- JavaScript事件被解雇,做一些事情(例如
的console.log()
) - 最后,执行页面加载
此外,这将是巨大的,如果这也触发重新加载页面(如pressing F5)用户事件的作品。
我认识到,有#2类似的东西在这里。它示出了加载另一个页中是否有一个回答框未保存内容之前警报。这可能是相同的功能我问。
If a user moves away from the current page by using mouse (clicking on a link) or keyboard (hitting enter while having a form element focused) interactions, i want to do be able to run JavaScript/jQuery commands beforehand.
Exemplary workflow:
- User clicks on any link or hits a key which will result in loading a new page in the browser
- A JavaScript event gets fired and does something (for example
console.log()
) - Finally, the page load is executed
Furthermore, it would be great if that also works with user events that trigger a page reload (like pressing F5).
I realize that there is something similar here on Stackoverflow. It shows an alert before loading another page if there is unsaved content in an answer box. That may be the same functionality i ask for.
这篇关于jQuery的:控制页面重载或从当前页面搬走的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!