thelinuxer
thelinuxer

Reputation: 670

Get list of opened popup windows

I would like to know if I can get a list of popups opened by window.open javascript function call.

I want to run some code after all these pages are closed. I don't mind if the solution was plain javascript or JQuery.

Thanks in advance.

Upvotes: 5

Views: 8523

Answers (2)

moeiscool
moeiscool

Reputation: 1426

you can use localstorage to do this. I am also using a localstorage plugin so the set and get are short hand.

function Op(r,rr,rrr){
    if(!rrr){rrr={};};if(!rrr.n){rrr.n='PopUps'}
    ii={o:jQuery.localStorage.get(rrr.n)}
    if(!ii.o){
        switch(rrr.n){
            case'unmOptions':
                ii.o={audio0:1,audio1:1}
            break;
            default:
                ii.o={p:{}}
            break;
        }
    }
    if(r&&rr&&!rrr.x){
        ii.o[r]=rr;
    }
    switch(rrr.x){
        case 0:
            delete(ii.o[r])
        break;
        case 1:
            delete(ii.o[r][rr])
        break;
    }
    jQuery.localStorage.set(rrr.n,ii.o)
    return ii.o
}

How to get object of windows

Op()
Op().p['window1']

to set values

Op('key','value')

to delete values

Op('key','',{x:0})

Upvotes: -3

T.J. Crowder
T.J. Crowder

Reputation: 1075079

No, you can't get a list of windows opened by the page via window.open (sadly). You'll have to keep track of them as you open them (assuming it's you who opens them).

If you were to do the more modern style of popup instead (positioned elements opened as virtual windows within the page), then of course you could readily get a list of them by doing a simple selector query (just add a class to them when they're showing, and then query the DOM for elements with that class).

Upvotes: 5

Related Questions