views:

47

answers:

2

I am using GreyBox for opening a new HTML page in the same window. It's working fine but now I want that it should get closed on pressing escape or if a user clicks somewhere else on the page. How can I do that?

edit:---

document.onkeypress = function (event) {
  if (event == undefined) { event = window.event; }
if (event.keyCode == 27) {
  AJS.AEV(document,"keypress",GB_hide);
  }
 }

i used this and it runs fine on mozilla but not on safari or chrome.... any idea why is thats so??

A: 

Perhaps this helps you?

window.document.onkeydown = function(evt) {
    if (evt.keyCode == 27) {
        if (alert.open) {
            alert.close();
        }
    }
}
Jan-Frederik Carl
Don't forget to normalize the Event interface...
Marcel Korpel
plz see my edit.
developer
A: 

this did the trick.

document.onkeypress = function noNumbers2(e){
    e = e || window.event;
    var keynum = e.keyCode || e.which;
    if(keynum == 27){
  AJS.AEV(document,"keypress",GB_hide);
  }
}
developer