Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将打开的弹出窗口放入数组中,并在每次创建新弹出窗口时使它们都位于顶部?_Javascript_Html_Arrays_Popup - Fatal编程技术网

Javascript 如何将打开的弹出窗口放入数组中,并在每次创建新弹出窗口时使它们都位于顶部?

Javascript 如何将打开的弹出窗口放入数组中,并在每次创建新弹出窗口时使它们都位于顶部?,javascript,html,arrays,popup,Javascript,Html,Arrays,Popup,所以打开我使用的弹出窗口 <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+',

所以打开我使用的弹出窗口

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

openWin=函数(名称、宽度、高度、左侧、顶部){
左=左+1;
顶部=顶部+1;
var file='./'+name+'.flv?action=read';
变量设置=“宽度=”+width+”,高度=“+height+”,左=“+left+”,顶部=“+top+”,屏幕X=”+left+”,屏幕Y=“+top+”;
//警报(文件);
//警报(设置);
var win=window.open(文件、名称、设置);
}

我想知道如何在打开新窗口时将弹出窗口放入数组,并在每次创建新窗口时将所有已创建的弹出窗口置于其顶部?

只需创建一个空数组来存储每个窗口即可。在数组中创建一个新的单循环并调用每个窗口的
focus
方法后:

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();
    }
})();
var openWin=(函数()
{
var弹出窗口=[];
返回函数(名称、宽度、高度、左侧、顶部)
{
++左;
++顶部;
var file='./'+name+'.flv?action=read';
变量设置='width='+width+'、height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
push(window.open(文件、名称、设置));
对于(变量i=0;i

您可能希望将所有内容都放在一个闭包中,这样阵列就不会暴露。

hM。。。我尝试使用'var windows=[];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+',screenX='+left+',screenY='+top+';windows.push(window open(file,name,settings));for(var i=0;iwins,使用了wins.length而不是windows.length(),对不起,这是我的错。我有一段时间没有使用JS了,我认为length是一种方法。不管怎样,我测试了它,它可以工作()至少在FireFox上是这样。你有没有想过在同一个文档中使用模式对话框层而不使用弹出窗口?在这个时代使用弹出窗口是一种不好的做法,因为浏览器现在在其安全模型中添加了弹出窗口拦截器和限制。