views:

385

answers:

2

Hi,

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?

Thanks.

+3  A: 

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.

Jonathan Fingland
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
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
There's just not a good way to do this in a browser.
overstood
Jonathan, I managed to identify alt enter compound. but couldn't stop event from bubbing using "event.cancelBubble", "event.returnValue".
Ramiz Uddin
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
Thanks Jonathan. Could you please provide reference so I could send that to my client.
Ramiz Uddin
See http://msdn.microsoft.com/en-us/library/ms533075%28VS.85%29.aspx User Applicability Note #2
Jonathan Fingland
A: 

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.

BlackAceDesign.com