如何通过浏览器后退按钮控制 [英] How to control over browser back button

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

问题描述

我想在浏览器后退按钮的点击确认窗口。如果我preSS是那么previous页面会加载ortherwise我会留在同一页面?

I want a confirmation window on click of a browser back button. If I press yes then the previous page will get load ortherwise I will remain in the same page?

任何建议是高度AP preciated ..但请正轨..我的问题是直线前进

Any suggestion is highly appreciated.. But please be on track.. my question is straight forward

THX提前..

推荐答案

你为什么要这么做?

您可以通过使用Javascript离开页面prevent他们,但如果你不能使用,这是不可能做任何事情了。

You can prevent them from leaving the page by using Javascript, but if you can't use that, it's not possible to do anything about it.

通常你应该使用在体内的卸载事件(jQuery中例如,只需添加

Generally you should use the unload event in the body (in jQuery for instance, just add

jQuery(window).unload(function(evt){
   if(!confirm('Do you really want to leave')){
      evt.preventDefault();
   }});

原型有类似的东西,而对于纯JavaScript,我想,它仍然取决于你使用的浏览器,但 window.unload =功能(EVT){返回false;} 可能的工作。

不记得它正确的语法虽然。

Don't remember the correct syntax for it though.

但我不知道是否可以限制为只有回来,如果它会触发所有的卸载(如点击链接,关闭浏览器等)

but I do not know if you can limit that for only the back or if it will trigger for all the unloads (like clicking on a link, closing the browser etc.)

如果你想阻止他们,因为他们可能在一个窗体未保存的数据,然后就是确定。如果你想从回去的另一个原因比阻止他们,我想你应该反思一下为什么。

If you want to stop them because they might have unsaved data in a form, then that is ok. If you want to stop them from going back for another reason than that, I think you should rethink why.

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

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