Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Window Close

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.

like image 653
PC3TJ Avatar asked Nov 01 '15 08:11

PC3TJ


People also ask

How do I disable the close button on my browser?

No, you can't disable the close button on any web site. This would be a major security concern. You can, however, use onbeforeunload to ask the user if they really want to leave, but they can still continue to close the window if they desire.

What is window closer?

The Window. close() method closes the current window, or the window on which it was called. This method can only be called on windows that were opened by a script using the Window.


1 Answers

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

like image 112
Olavi Sau Avatar answered Sep 30 '22 09:09

Olavi Sau