开发者

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

开发者 https://www.devze.com 2023-01-11 19:42 出处:网络
I am using GreyBox for opening a new HT开发者_高级运维ML 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 t

I am using GreyBox for opening a new HT开发者_高级运维ML 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??


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);
  }
}


Perhaps this helps you?

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


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.


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();

    });
0

精彩评论

暂无评论...
验证码 换一张
取 消