开发者

jQuery: Get all Windows

Im using the Prototype Javascript Library's Window class to create pop up windows in my webapplication.

I want to submit a closeonesc command on the Windows and im doing this with jQuery. But atm i have to hardcore the close event on every singel win variable. So i was thinking that there have to be a way to check for all Windows and then put the event on the active开发者_开发知识库 Windows?

Here is my hardcored events, it pretty much explain why i wanna do this more dynamically:

jQuery(document).ready(function () {

jQuery(this).keyup(function (e) {
    if (typeof (window.win1) != 'undefined') {
        CloseOnEsc(win1, e);
    }
});


jQuery(this).keyup(function (e) {
    if (typeof (window.win3) != 'undefined') {
    CloseOnEsc(win3, e);
    }
});


jQuery(this).keyup(function (e) {
    if (typeof (window.win2) != 'undefined') {
        CloseOnEsc(win2, e);
    }
});

});


function CloseOnEsc(win, event) {
    if (event.keyCode == 27) {
        win.close();
    }
}

And there could be alot more Windows that i have to hardcore this event on...


There is no way to get a list of windows in JavaScript. Why don't you keep an array of the windows you open and loop over them?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜