使用javascript/jquery检测android后退按钮 [英] Use javascript/jquery detect android back button

查看:78
本文介绍了使用javascript/jquery检测android后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我想制作一个函数来检测android后退按钮是否被按下,并对其进行处理.

Currently I want to make a function to detect android back button is pressed and do some stuff on it.

1)用户打开应用程序,然后单击一个按钮.该按钮使用户可以打开网站.

1) User opens the apps, and clicks a button. This button lets the user to open a website.

2)用户填写了第2页上的信息,并且他想返回上一页,他单击了Android手机上的后退"按钮.

2) User fills in the information on page 2 , and he wants to go back the previous page, he clicks the back button on android phone.

3)后退"按钮可帮助用户关闭网站并返回我的应用程序,而不是返回第1页.

3) The back button helps user close the website and go back to my apps instead of back to page 1.

有人可以告诉我如何使用jqueryjavascript检查用户按下的后退按钮吗?这样我就可以防止后退"按钮关闭网站,而是重定向到另一个页面.

Can someone tell me how to do with jquery or javascript to check the back button pressed by user? So that I can prevent the back button close the website but redirect to another page.

是否可以检测到浏览器android后退按钮事件?我想覆盖android后退按钮的默认设置,并在其中添加一些代码.

PS:未使用Java.

  • 顶部的后退按钮(浏览器后退按钮)可以返回到上一页.
  • 底部的后退按钮(后退电话)帮助我关闭网站.
  • 我要使底部的后退按钮也返回上一页.

参见此

谢谢.

推荐答案

您需要覆盖WebView活动上的onBackPressed,并检查webview是否可以返回.

You need to override the onBackPressed on WebView Activity and check if webview can go back or not.

@Overide
public void onBackPressed(){
  if(webview.canGoBack())
   webview.goBack();
  else
   super.onBackPressed();
}

更新:

给出此答案时,问题不是特定于仅Javascript" 非Java编码" 等,即仅由后端处理. 严格来说,此答案仅适用于Android端,而不适用于后端.如果有人来自Android,我会保留此答案.

When this answer was given question was not specific for "Javascript only" and "not coding in Java", etc.. i.e. handle only by backend. This answer is strictly for Android side not for backend side. I am keeping this answer if someone from Android need this answer.

这篇关于使用javascript/jquery检测android后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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