Javascript:onrefresh还是onreload? [英] Javascript: onrefresh or onreload?

查看:706
本文介绍了Javascript:onrefresh还是onreload?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个在用户点击重新加载时触发的事件处理程序。是onrefresh还是onreload要添加的正确处理程序?此外,这还会在onunload之前或之后开火吗?浏览器是否存在不一致之处?谢谢。

I want an event handler that fires when the user hits reload. Is onrefresh or onreload the correct handler to add to ? Also, will this even fire before or after onunload? Are there an browser inconsistencies? Thanks.

推荐答案

我认为没有名为onrefresh或onreload的事件。您可以知道页面何时卸载,但知道原因(即用户下一步的位置)是在JavaScript的安全沙箱之外。了解页面是否已重新加载的唯一方法是知道用户在最后一页请求中的位置,这也超出了JavaScript的范围。您有时可以通过 document.referrer 获取,但它依赖浏览器的安全设置来允许访问该信息。

I don't think there are events called onrefresh or onreload. You can know when the page is unloading, but knowing why (i.e. where the user is going next) is outside JavaScript's security sandbox. The only way to know whether the page has been reloaded is to know where the user was on the last page request, which is also outside the scope of JavaScript. You can sometimes get that via document.referrer, but it relies on the browser's security settings to permit access to that information.

这篇关于Javascript:onrefresh还是onreload?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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