开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜