问题
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