6

We have a Point of Sale product that runs in the browser(specifically chrome Kiosk mode). We want to prevent the user from being able to close the window without a pin number. In kiosk mode of course the only way to exit is to either end the process or use alt+f4 so right now our solution is not attatching keyboards to any POS terminals. Just hoping that there may be another solution.

edit: Also to mention I have complete root access on every terminal this web app is being run on. So any chrome flags, etc... can be added.

As mentioned before, I was asking for what ways i could prevent the window from closing all together not simply intercepting unload event and asking for confirmation.

PC3TJ
  • 852
  • 5
  • 16
  • 1
    Possible duplicate of [Intercept page exit event](http://stackoverflow.com/questions/1704533/intercept-page-exit-event) – Olavi Sau Nov 01 '15 at 08:52
  • @OlaviSau these are not duplicates. I was looking for a way to prevent close altogether instead of prompting the user to confirm as I thought this would be possible as I have root access to all machines running this kiosk system – PC3TJ Jun 10 '16 at 04:49

2 Answers2

9

There is no way to completely stop it, the best you can do is confirm the leaving.

  window.onbeforeunload = function (e) {
  var message = "Your confirmation message goes here.",
  e = e || window.event;
  // For IE and Firefox
  if (e) {
  e.returnValue = message;
  }

  // For Safari
  return message;
};

Answer from Intercept page exit event

About alt+f4 refer to this: Disable ALT+F4, yes I know it isn't recommended

Community
  • 1
  • 1
Olavi Sau
  • 1,647
  • 13
  • 20
  • I figured that would be the answer. By any chance do you know if everything inside a function fired by window.onbeforeunload will be executed prior to the window closing. Such as putting all unsaved data and session keys into a cookie. – PC3TJ Nov 01 '15 at 08:51
  • Yeap all the code will be executed, but if the user wants to leave, you can't get any additional input from him. – Olavi Sau Nov 01 '15 at 08:54
  • It is prefereble to use `addEventListener('beforeunload', function() {})` then `window.onbeforeunload = function() {}`, as the latter can overwrite previous functions assigned to `onbeforeunload`. – Flimm Mar 08 '22 at 14:37
0

You could prevent navigating away with window.onbeforeunload until a pin is entered.

friendOfOURS
  • 25
  • 2
  • 6
  • window.onbeforeunload() only allows you to ask the user if they want to leave though. If they say yes then I can't prevent that – PC3TJ Nov 01 '15 at 08:50