使用javascript处理刷新页面事件 [英] Handle refresh page event with javascript

查看:106
本文介绍了使用javascript处理刷新页面事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用javascript来处理刷新页面的事件?
我想要的是如果用户执行以下行为之一就会收到通知:

Is it possible to use javascript to handle the event of refreshing page? What i want is get notice if user do one of these behaviours:


  • 按F5刷新页面

  • 关闭标签或浏览器

  • 输入新网址然后按
    浏览器上的输入

显示警告信息?

提前致谢!

to display a warning message?
Thanks in advance!

推荐答案

你不希望刷新,你想要onbeforeunload事件。

You don't want the refresh, you want the onbeforeunload event.

http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx

文章中的示例代码

<HTML>
<head>
<script>
function closeIt()
{
  return "Any string value here forces a dialog box to \n" + 
         "appear before closing the window.";
}
window.onbeforeunload = closeIt;
</script>
</head>
<body>
  <a href="http://www.microsoft.com">Click here to navigate to 
      www.microsoft.com</a>
</body>
</html>

这篇关于使用javascript处理刷新页面事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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