How to put opened popUps into array and make them all on top each time new one is created?

我的未来我决定 提交于 2020-01-07 05:27:54

问题


So to open popUps I use

<script>
openWin = function(name, width, height, left, top){
    left=left+1;
    top=top+1;
    var file='./'+name+'.flv?action=read';
    var settings='width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top+'';
    //alert(file);
    //alert(settings);
    var win = window.open(file, name, settings);
}
      </script>

I wonder how to put popUps into array when opening new one and make all created popUps on top each time new one is created?


回答1:


Just create an empty array to store each window. After creating a new one loop through the array and call each window's focus method:

var openWin = (function ()
{
    var popups = [];
    return function (name, width, height, left, top)
    {
        ++left;
        ++top;
        var file = './' + name + '.flv?action=read';
        var settings = 'width=' + width  + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
        popups.push(window.open(file, name, settings));
        for (var i = 0; i < popups.length; ++i)
            popups[i].focus();
    }
})();

You may want to put everything inside a closure, so the array won't be exposed.



来源:https://stackoverflow.com/questions/4349837/how-to-put-opened-popups-into-array-and-make-them-all-on-top-each-time-new-one-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!