Pages

Friday, January 7, 2011

Getting Key Strokes on XPages (eg. Enter Key Press)

Most javascript resources on the web said some thing similar to the following to capture key strokes.

var key;
if(window.event)
key=window.event.keyCode;
else
key=e.which //for firefox explicitly on XPages

But the same failed in case of XPages in Firefox and I was puzzled

After a long try I found the following fix which worked for client, web-IE/Firefox/Chrome. The trick is bolded in the following code

var key;
if(window.event)
key=window.event.keyCode;
else
key=thisEvent.which //for firefox explicitly on XPages

//if enter key is pressed proceed or else skip
if (key == '13') {
alert("Enter Key Pressed");
}

Hope this helps :)

2 comments: