如何查找浏览器后退按钮事件? [英] How to find browser back button event is fired?

查看:92
本文介绍了如何查找浏览器后退按钮事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


有没有办法找到这个活动是浏览器返回按钮点击?


我需要显示提醒当用户点击浏览器后退按钮?我尝试使用以下代码,但此页面上的每个事件都显示警告。

Hi All,

Is there any way to find the event is browser back button click?

I need to show an alert when user clicks on browser back button? I tried using the following code but alert is showing for every event on this page.

展开 | 选择 | Wrap | 行号

推荐答案

嗨bHappy,


在IE中,您可以在PageX,PageY的帮助下找到,但在Mozilla中很难找到点击浏览按钮。相反,您可以使用 window.onbeforeunload 处理程序本身。您只在某些页面中使用此处理程序,您希望用户在导航到其他页面之前执行某些操作。
Hi bHappy,

In IE, you can find with the help of PageX, PageY but in Mozilla its difficult to findout the click of browse button. Instead you can use the window.onbeforeunload handler itself. You use this handler for only some pages where you want the user to save the datas are do something before he navigate to other page.


您好,

感谢您你的回复,

我只在一个页面中使用这个代码,我有保存,更新,取消按钮和左侧菜单中也有一些链接。我的问题是警告msg显示我是否也点击任何链接或按钮。


Plz有些身体帮我...


谢谢。
Hi,
Thanks for ur reply,
I am using this code in only one page where i had save, update, cancel buttons and some links also available in left side menu. My problem is alert msg is showing if i click any link or button also.

Plz some body help me...

Thanks.


好吧,所有这些元素都会触发此事件(在行为正确的情况下)。基本上按后退按钮就像使用链接?也许你可以通过事件目标进行区分。
well, all these elements trigger this event (insofar the behaviour is correct). basicly pressing the back button is like using a link? maybe you can differentiate by the event target.


这篇关于如何查找浏览器后退按钮事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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