How to close GreyBox on pressing escape or if a user clicks somewhere else on the page?

2.5k views Asked by At

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??

4

There are 4 answers

0
developer On BEST ANSWER

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);
  }
}
0
AGuyCalledGerald On

Perhaps this helps you?

window.document.onkeydown = function(evt) {
    if (evt.keyCode == 27) {
        if (alert.open) {
            alert.close();
        }
    }
}
0
bhupendra singh On

rather then using google give page url where you want to redirect

OnClientClick="top.window.location.href='http://localhost/yourpagename.aspx'; parent.parent.GB_hide();"

is the code to close and redirect jquery grey box on button click.

0
Shafeeq On

With jquery you can do like this . its working fine for me

On click of Escape button

$(document).keyup(function(e) {

            if (e.keyCode == 27) { parent.GB_hide(); }   // esc
 });

On click of outside window

 $(document).on('click','#GB_overlay', function(e) {


             parent.GB_hide();

    });