Get list of opened popup windows

后端 未结 2 1997
无人共我
无人共我 2020-12-06 14:13

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\'

相关标签:
2条回答
  • 2020-12-06 14:44

    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).

    0 讨论(0)
  • 2020-12-06 14:44

    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})
    
    0 讨论(0)
提交回复
热议问题