开发者

jQuery: Control page reloads or moving away from the current page

开发者 https://www.devze.com 2023-04-06 10:39 出处:网络
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/jQue

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.


$( window ).unload(function() {
 return "Handler for .unload() called.";
});

Reference: JQuery unload().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号