jQuery的:控制页面重载或从当前页面搬走 [英] jQuery: Control page reloads or moving away from the current page

查看:173
本文介绍了jQuery的:控制页面重载或从当前页面搬走的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户通过使用鼠标(点击链接)或键盘(按回车键,同时有一个表单元素集中)的互动,我想这样做能够运行JavaScript / jQuery的预先命令。<移动从当前页面离开/ p>

示范性的工作流程:


  1. 用户点击任何链接或点击一个按键,这将导致在浏览器中加载新页

  2. JavaScript事件被解雇,做一些事情(例如的console.log()

  3. 最后,执行页面加载

此外,这将是巨大的,如果这也触发重新加载页面(如pressing F5)用户事件的作品。

我认识到,有#2类似的东西在这里。它示出了加载另一个页中是否有一个回答框未保存内容之前警报。这可能是相同的功能我问。


解决方案

JQuery的卸载()

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:

  1. User clicks on any link or hits a key which will result in loading a new page in the browser
  2. A JavaScript event gets fired and does something (for example console.log())
  3. 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 unload().

这篇关于jQuery的:控制页面重载或从当前页面搬走的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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