如何在javascript中处理设备后退按钮 [英] How to handle device back button in javascript

查看:58
本文介绍了如何在javascript中处理设备后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.net网站,我想处理移动后退按钮,无需在javascript或jquery中重新加载页面

推荐答案

你可以使用页面上的 window.history.forward()。但问题是了解它的作用。

history.forward()将用户移动到历史记录中的下一个URL /页面。如果历史记录中没有URL /页面,它只是什么都没有,它将无法工作。

禁用浏览器后退按钮是混乱浏览器的功能。

返回上一页或下一页是任何浏览器的默认行为。所以我们很难操纵很多功能。所以,我想我们可以通过将Url限制为历史记录中的下一个Url来阻止后退按钮被触发。

另一种情况是,如果您不想将Url存储在页面历史记录中,您可以使用以下代码:

You can use window.history.forward() on the page. But the thing is to understand what this does.
history.forward() moves the user to the next URL/Page that is in the history. If no URL/Page is there in the history, it simply gives nothing, it will not work.
And disabling the browsers Back button is to mess with browser's functionality.
Going back to the previous page or next page is the default behaviour of any browser. So we can hardly manipuate much of the functionalities. So, I guess we can prevent the back button getting fired by restricting the Url to the very next Url in the History.
Another case is if you want not to store the Url in the history of the page you can use the following bit of code:
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)



这里我们从程序中过期缓存,即清除缓存。



希望你能从中得到一些建议。

谢谢。

:)


Here we expire the cache from the program, i.e. clear the cache.

Hope you get some idea from this.
Thanks.
:)


if(event。 keycode == 27)它适用于移动???我想只隐藏移动后退按钮上的菜单,如果没有页面返回页面....是否可以在jquery中的移动后退按钮上添加操作
if(event.keycode==27) is it works for mobile ??? i want to only hide the menu on mobile back button and if not page goes back page.... is it possible to add action on mobile back button in jquery


这篇关于如何在javascript中处理设备后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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