H
HopfZ
I tried to detect modifier+enter key press in textarea in Firefox,
Opera and IE. The code is at the end. The result is
Firefox 1.5 : shift+enter, ctrl+enter, alt+enter all detected.
Opera 9 beta : shift+enter, ctrl+enter detected. alt+enter is
reserved for the browser.
Internet Explorer 6 : only shift+enter is detected.
Why e.ctrlKey and e.altKey are not being detected in IE? Is it by
design?
<html>
<head>
<script type="text/javascript">
function load(){
var ta = document.getElementById('ta');
ta.onkeypress = taKeyPress
ta.focus();
}
function taKeyPress(e){
var e = e || window.event;
var hasMod = e.shiftKey || e.ctrlKey || e.altKey;
var unicode = e.charCode || e.keyCode;
if(hasMod && unicode==13 /*hasMode and enter key*/){
alert('detected');
return false;// cancel key press.
}
}
</script>
</head>
<body onload="load()"><form>
<textarea id="ta">textarea</textarea>
</form></body>
</html>
Opera and IE. The code is at the end. The result is
Firefox 1.5 : shift+enter, ctrl+enter, alt+enter all detected.
Opera 9 beta : shift+enter, ctrl+enter detected. alt+enter is
reserved for the browser.
Internet Explorer 6 : only shift+enter is detected.
Why e.ctrlKey and e.altKey are not being detected in IE? Is it by
design?
<html>
<head>
<script type="text/javascript">
function load(){
var ta = document.getElementById('ta');
ta.onkeypress = taKeyPress
ta.focus();
}
function taKeyPress(e){
var e = e || window.event;
var hasMod = e.shiftKey || e.ctrlKey || e.altKey;
var unicode = e.charCode || e.keyCode;
if(hasMod && unicode==13 /*hasMode and enter key*/){
alert('detected');
return false;// cancel key press.
}
}
</script>
</head>
<body onload="load()"><form>
<textarea id="ta">textarea</textarea>
</form></body>
</html>