开发者

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

So to open popUps I use

<script>
openWin = function(name, width, height, left, top){
    left=left+1;
    top=top+1;
    var file='./'+name+'.flv?act开发者_JAVA百科ion=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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜