Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何用原型检测“刷新”事件?跨浏览器解决方案?
谢谢, 塞尔索
没有办法特别检测刷新,但您可以在页面卸载之前捕获浏览器(当用户刷新页面时发生这种情况 - 以及当他们“移动”到另一个页面时)
在原型中,这看起来像这样:
Event.observe(window, 'beforeunload', yourFunction);
如果您需要区分,您始终可以将一些代码绑定到页面上的链接,以禁用上述绑定,以便当用户主动单击某些内容时,您知道这是一个链接(而不是刷新)。