-1

In my website in a particular workflow, a screen appears with payment options and a timer starts.

From this screen onward if user tries to refresh the page or go back to the previous page, then user should be redirected to home page.

To implement this functionality what could be the easiest way?

Please consider this website is built using mvc5

priyam
  • 25
  • 1
  • 11
  • You can achieve it with JS, document.onkeypress event, track the keys you want to validate against, though the best way for payment related pages are to display the page as the new pop out page, where you have option to lock the tool bar. – foo-baar Aug 30 '14 at 18:02
  • This solution doesn't work. If a user forces popups to open in a new tab, you'll have people overriding your controls and still able to refresh. Same with mobile devices, every popup will have a toolbar. – Andrew Tran Aug 30 '14 at 19:46

2 Answers2

1

I saw the word "payment" over there, since there could be money involved (directly or not) I would strongly recommend that you make all your logic checks on the server.

If you know what is each user doing, then you can redirect them to the right place.

This could not be the answer to yor question, but I guess it is part of an answer to your problem.

Felipe Pereira
  • 11,410
  • 4
  • 41
  • 45
0

Found this in the answer located here.

<script type="text/javascript">
    window.onbeforeunload = function() {
        return "Dude, are you sure you want to leave? Think of the kittens!";
    }
</script>

Also, this may help:

Community
  • 1
  • 1
Richard Barker
  • 1,161
  • 2
  • 12
  • 30
  • Thanks @Richard Barker. However also found the following comment in the same post: 'Just a note that the onbeforeunload event is not available in versions of the Opera browser. ' – priyam Aug 30 '14 at 17:56
  • You may also consider the answer below the above mentioned answer specifying a way to prevent the a reload event fired by the F5 key. – Richard Barker Aug 30 '14 at 18:04