keys.js
799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function getElem(event)
{
// Retrieve the event in IE
if (!event)
var event = window.event;
// Reference the element howeaver this browser can
var elem;
if (event.target) // For Firefox
elem = event.target;
else if (event.srcElement) // For IE
elem = event.srcElement;
if (elem.nodeType == 3) // For Safari
elem = elem.parentNode;
return elem
}
function keyHandler(event)
{
// for IE
if (!event)
var event = window.event
var srcElement = getElem(event)
var tag = srcElement.tagName;
var override = !(tag == "A" || tag == "INPUT" || tag == "SELECT" || tag == "FORM" || tag == "SUBMIT");
if (override && event.keyCode == 13) //13 is <enter> key
{
if (srcElement.click)
srcElement.click();
else
srcElement.onclick();
}
}
document.onkeypress = keyHandler;