0

As the default behavior of IE is to switch to the full screen mode on Alt-Enter command. I've to avoid this and have to attach a custom behavior.

Is it doable?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ramiz Uddin
  • 4,249
  • 4
  • 40
  • 72

2 Answers2

3

Not in JavaScript, no.

This is a behaviour of the application, which you don't really have control over (aside from browser extensions, and such).

You could try catching the key presses on your page, but it wouldn't prevent the user from easily circumventing it.

See http://www.webonweboff.com/tips/js/event_key_codes.aspx for a list of the character codes for keys. I'm pretty sure it's not reliable for catching combinations of key presses.

Besides, Alt+Enter in IE results in an expected behaviour and you should not try to override this via a webpage.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
Jonathan Fingland
  • 56,385
  • 11
  • 85
  • 79
  • But I don't have a choice. I've to implement each and every feature and this is just one from them :(. I know blocking default event is not a right practice and shouldn't be done. But things have to be deliver this way :) – Ramiz Uddin Oct 20 '09 at 07:29
  • you're up against a technical barrier as well. You *could* maintain a state variable for ALT (set true when keydown, and false on keyup) and a state variable for enter (ditto on conditions), and check if both state variables are true, and *try* to `return false` to prevent the default action. Chances are, IE's handling of that key combination will take precedence over whatever the page wants to do. – Jonathan Fingland Oct 20 '09 at 08:30
  • Jonathan, I managed to identify alt enter compound. but couldn't stop event from bubbing using "event.cancelBubble", "event.returnValue". – Ramiz Uddin Oct 20 '09 at 08:41
  • as I figured. IE prevents this kind of abuse. You'll just have to tell your client/employer that it is not possible and look at alternatives – Jonathan Fingland Oct 20 '09 at 08:51
  • Thanks Jonathan. Could you please provide reference so I could send that to my client. – Ramiz Uddin Oct 20 '09 at 08:59
  • 1
    See http://msdn.microsoft.com/en-us/library/ms533075%28VS.85%29.aspx User Applicability Note #2 – Jonathan Fingland Oct 20 '09 at 11:09
0

Since you can't beat 'em, join 'em. Meaning, since you can catch the event but can't stop it, how about you just run the same command in a timeout after the user presses alt+enter?

Example:

<script type="text/javascript">

document.onkeydown = handleHotKeys;

function handleHotKeys(e) {
    var keynum = getKeyCode(e);
    var e = e || window.event;
    if (keynum==13 && e.altKey) { // handle enter+alt
        setTimeout("toggleFullscreenMode",100);
    }

}
function getKeyCode(e){
    if (!e)  { // IE
        e=window.event;
        return e.keyCode;
    } else { // Netscape/Firefox/Opera
        return e.which;
    }
}

function toggleFullscreenMode() {
  var obj = new ActiveXObject("Wscript.shell");
  obj.SendKeys("{F11}");
}
</script>

DISCLAIMER: Tested in IE8. You will have to look at the browser and version to get this to work for the specific version of the browser you are targeting. This also assumes that the user will have javascript and activex objects enabled.

Dan J
  • 225
  • 3
  • 9
  • This would only work if the user had enabled unsafe ActiveX controls (e.g. WScript.Shell), and thus isn't suitable for any Internet or Intranet page. – EricLaw Nov 13 '12 at 17:41