问题
I have gone through the following link and my situation is same like it.
Disable hardware back function jquery mobile
Situation: Device under test : Samsung S3
Page A: ListView with Names(A1, A2, A3) Page B: Consist of Form, Submit and Cancel button.
User fills the form and click on submit button. And his data gets uploaded to server. Page is updated and Confirmation dialog is displayed that data is uploaded to server.
Now the Issue arrives.
Now when the user clicks on Hardware back button he is again redirected to Page B and he is again able to submit the form (which we don't require, as the form is meant to be filled only once).
So is there any way through which I can control the hardware back button to show Page A whenever it is on Page B.
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.
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.
Can some one help me out.
回答1:
You should be able to capture 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...
}
});
回答2:
Use cookies. whenever the form is processed add a value to the user's cookie and on the form page check if that cookie value exists. If it does just show the user a message which indicates that the data have already been submitted or redirect the user to the main page.
回答3:
What I did was to Include the Login form and the page the user is directed after login, in the same html file as two pages (multi-page containers). After validating the login, I call the changePage to the id of the new page i want to load with changeHash as false. This way the user won't be returned to the login even by the hardware back button.
来源:https://stackoverflow.com/questions/12859759/take-control-of-hardware-back-button-jquery-mobile