7

I have gone through the following link and my situation is same like it.

Disable the hardware back function with jQuery Mobile

Situation: Device under test: Samsung Galaxy S III

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.

Now the issue arrives.

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).

So is there a 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.

How can I fix this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1551578
  • 73
  • 1
  • 2
  • 4
  • Possible duplicate: *[Disable the hardware back function with jQuery Mobile](https://stackoverflow.com/questions/11425820/disable-the-hardware-back-function-with-jquery-mobile)* – Peter Mortensen Aug 31 '21 at 16:16

3 Answers3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

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...
  }
});
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pablo
  • 2,834
  • 5
  • 25
  • 45
  • I am working on Samsung galaxy S3 mobile, I guess this is for Keyboard – user1551578 Oct 12 '12 at 14:26
  • I have tested it with a Samsung GT-S5570 (without keyboard) and works. – Pablo Oct 12 '12 at 14:43
  • Hi I am still having problem, could you please tell me where should i ass this code in my code. – user1551578 Oct 15 '12 at 05:07
  • Do it before loading jQueryMobile javascript file. Event should be bind to the `document`, so that it captures all events of `keydown` (and hardware back button should produce this event). – Pablo Oct 15 '12 at 07:01
  • But it worked with a blackberry which has a bac button not with my Samsung Galaxy Ace S5830i. Anyways thanks for helping out. – user1551578 Oct 16 '12 at 07:18
  • For me it is working for both platforms (for Blackberry I have tested it in a 9810 device). I don't know any other way to do it... sorry I could not help more. – Pablo Oct 16 '12 at 07:43
  • This event gets triggered on desktop browser when pressing the backspace key but not the back button on Galaxy Ace. Desktop browser's graphical back button also does not trigger this event so can only guess that the Galaxy Ace's back button is the same as the browser's graphical back button. Solution must be non-device/browser specific – the_new_mr Mar 12 '13 at 14:31
1

I included 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
akhil_
  • 233
  • 1
  • 4
  • 10