Biff MaGriff
Biff MaGriff

Reputation: 8241

What are the means I can use to disable Alt + *X* in Internet Explorer?

Essentially, in our system, our users enter reports and they find all manners of ways to accidentally lose their work on them so we have been locking down everything that they can press that might make them lose data. F5, CRTL + R, CTRL + W and Backspace are all disabled; all bars in IE are hidden and there is a confirmation dialog on the close button.

I have not had any luck in disabling ALT + F4, ALT + ←, ALT + →

I have tried disabling them with javascript. However my method is not working.

if (window.event.altKey) {
    if (window.event.keyCode == 115) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
        window.event.keyCode = 0;
        window.status = "Alt + F4 is disabled on all popups";
        return false;
    }
}

I'm thinking I may require more drastic methods.

In this answer here, he suggests this may be possible with shdocvw.dll but I'm not sure what that would entail.

Is there a means to disable the Alt + X combination or perhaps work around I can exploit for them?

Upvotes: 0

Views: 1479

Answers (2)

CAFxX
CAFxX

Reputation: 30311

No, you can't disable those combinations - and for good security reasons (otherwise any webpage could potentially hijack your computer...).

Your best bets are (in decreasing order of functionality):

  • continually saving the work on the server (think Google Docs)
  • using client-side storage (WebStorage and the like)
  • implement a onBeforeUnload handler that asks for confirmation before navigating away from the page (or closing the browser)
  • forcing your users to use browsers that save the state of the page (including forms and whatnot) when exiting (examples include Firefox and, IIRC, Chrome)

Upvotes: 1

jbabey
jbabey

Reputation: 46647

You shouldn't mess with default browser behavior. If you're worried about users accidently closing the window, just use the onbeforeunload event:

window.onbeforeunload = function () {
    return 'You will lose all unsaved changes.';
};​

http://jsfiddle.net/jbabey/rPLWd/

Upvotes: 1

Related Questions