0

I have used two js files

<script type="text/javascript" src="js/areyousure/areyousure.js"></script>
<script type="text/javascript" src="js/areyousure/ays-beforeunload-shim.js"></script>

<script>
$(document).ready(function(){
    $("form").areYouSure();
});
</script>

The above is working only if any of the form input is changed.. I have a dual list box in my page. If I select one of the text and press back button the alert is not working. Is there any solution for this ? I have already used onbeforeunload. It did not work. There are some issues with it. Is there any other solution to solve this problem?

The back button is working only if there is change in form. If I have pop ups and pickers it's not working.

Py.
  • 3,499
  • 1
  • 34
  • 53
Bhanu
  • 155
  • 1
  • 2
  • 15
  • 2
    Think is duplicated; http://stackoverflow.com/questions/18211984/how-to-control-back-button-event-in-jquery-mobile – Astaroth Apr 14 '16 at 07:23
  • It's not clear what you want to do. – devd Apr 14 '16 at 07:26
  • I have field. I enter the value into it by using picker. I have changed the value and pressed back button.. so now i have to get pop up as i have changed .. but i am not getting.. I say that if dynamically created fields are not restricting back button – Bhanu Apr 14 '16 at 07:34
  • I have an icon when it is clicked a pop up with text area is displayed.. then now i enter some text and i hit back button of browser,then i am not getting pop up alert. Because it is not in form right.. Dialogue opening is a special function right – Bhanu Apr 14 '16 at 07:42
  • No solution for this ? – Bhanu Apr 14 '16 at 08:43

1 Answers1

0

You're talking about the browser's back button I suppose. You should not attempt to listen to the backspace key or anything similar, as there are several ways to leave a page.

This would be the correct way.

window.addEventListener("beforeunload", function (event) {
  event.returnValue = "Are you sure?";
});

MDN

Jonathan
  • 8,771
  • 4
  • 41
  • 78
  • yea.. but when i use dual list box in it.. if i select any one and hit back button of browser,i must get an alert right.. but i am unable to get – Bhanu Apr 14 '16 at 07:37