如何检测“刷新”事件与原型? [英] How detect "refresh" event with prototype?

查看:190
本文介绍了如何检测“刷新”事件与原型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用原型检测刷新事件?谢谢,
Celso

解决方案

没有办法特别检测刷新,但是您可以在页面卸载之前抓住浏览器(当用户刷新页面时,以及何时移动到另一个页面)



在原型中,这看起来像这样:

  Event.observe(window, beforeunload',yourFunction); 

如果您需要说明差异,您可以随时将一些代码绑定到页面上的链接禁用上述绑定,以便当用户主动点击您知道的某个链接(而不是刷新)时。


How detect "refresh" event with prototype? A Cross-browser solution?

Thanks, Celso

解决方案

There's no way to detect refreshes in particular, but you can catch the browser before the page gets unloaded (which happens when the user refreshes the page - as well as when they 'move' to another page)

In prototype this would look something like this:

Event.observe(window, 'beforeunload', yourFunction);

If you need to tell the difference, you could always bind some code to the links on your page that disables the above binding so that when the user actively clicks something you know it's a link (and not a refresh).

这篇关于如何检测“刷新”事件与原型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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