使用 jQuery Mobile 控制硬件后退按钮 [英] Take control of the hardware back button using jQuery Mobile
问题描述
我已经浏览了以下链接,我的情况和它一样.
I have gone through the following link and my situation is same like it.
情况:被测设备:Samsung Galaxy S III
页面 A:ListView with Names(A1, A2, A3)
页面 B:由表单、提交和取消按钮组成.
Page A: ListView with Names(A1, A2, A3)
Page B: Consist of a Form, Submit and Cancel button.
用户填写表单并点击提交按钮.并且他/她的数据被上传到服务器.页面将更新并显示确认对话框,数据已上传到服务器.
The user fills in the form and click on the Submit button. And his/her data gets uploaded to the server. The page is updated and a confirmation dialog is displayed that data is uploaded to the server.
现在问题来了.
现在,当用户点击硬件后退按钮时,他/她再次被重定向到页面 B 并且他/她再次能够提交表单(我们不需要,因为表格只能填写一次).
Now when the user clicks on the hardware back button he/she is again redirected to Page B and he/she is again able to submit the form (which we don't require, as the form is meant to be filled only once).
那么有没有一种方法可以让我控制硬件后退按钮在页面 B 上显示页面 A?
So is there a way through which I can control the hardware back button to show Page A whenever it is on Page B?
Nirmal 的以下回答似乎有答案,但我不知道如何实现 -
The following answer from Nirmal seems to have answer, but I don't know how to implement it -
没有真正的方法禁用硬件上的后退按钮黑莓或安卓.
There is no real way disable the hardware back button on the BlackBerry or Android.
你可以做的是维护一个失效的会话变量在您的后台处理程序中并检查该会话变量考试页面的 pagebeforeshow 事件.
What you can do is maintain a session variable which gets invalidated in your back handler and check for that session variable in the pagebeforeshow event of the Exam page.
我该如何解决这个问题?
How can I fix this?
推荐答案
您应该能够使用 JavaScript 捕获硬件后退按钮单击事件:
You should be able to capture the hardware back button click event with JavaScript:
$(document).bind('keydown', function(event) {
if (event.keyCode == 27) {
// Prevent default (disable the back button behavior)
event.preventDefault();
// Your code to show another page or whatever...
}
});
这篇关于使用 jQuery Mobile 控制硬件后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!