如果窗口已经打开,请关闭它 [英] Close a window if it is already open

查看:54
本文介绍了如果窗口已经打开,请关闭它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从当前窗口打开一个新窗口来显示地图。


可以显示几个不同大小的地图。该函数的地图大小为

,并相应调整窗口大小。


如果新窗口已打开,则忽略新的地图大小并且新的

地图对于现有的新地图来说太小了。窗口或太大,这是一个更严重的问题!


我试图通过关闭新窗口来解决这个问题,如果它已经打开使用

下面的代码,但无济于事。似乎typeof(MapWindow)总是

undefined。该函数位于.js文件中。在.js文件中声明全局

变量是否可以?


任何帮助都非常感谢。


var MapWindow;

函数OpenMapWindow(src,vwidth,vheight)

{

if(typeof(MapWindow)!=" undefined" && MapWindow.closed == false)

{

MapWindow.close();

}

MapWindow = window.open(src," NewWindow"," width =" + vwidth +",height =" +

vheight +

" ;,left = 100,top = 100,resizable = no,toolbar = no,scrollb ars = no,menubar = no");

MapWindow.focus();

}

解决方案

Roger Withnell写道:

我从当前窗口打开一个新窗口来显示地图。 />
可以显示几个不同大小的地图。该函数给出了地图的大小并相应地调整了窗口大小。

如果新窗口已经打开,新的地图大小将被忽略并且新的
地图对于现有的新而言,它太小了窗口或太大,这是一个更严重的问题!

我试图通过关闭新窗口来解决这个问题,如果它已经打开使用
下面的代码,但无济于事。似乎typeof(MapWindow)始终未定义。该函数位于.js文件中。在.js文件中声明全局
变量是否可以?

任何帮助都非常感谢。

var MapWindow;
函数OpenMapWindow(src ,vwidth,vheight)
{
if(typeof(MapWindow)!=" undefined"&& MapWindow.closed == false)
{
MapWindow.close( );
}
MapWindow = window.open(src," NewWindow"," width =" + vwidth +",height =" +
vheight +
",left = 100,top = 100,resizable = no,toolbar = no,scrollb ars = no,menubar = no");
MapWindow.focus();
}




var MapWindow = null;

函数OpenMapWindow(src,vwidth,vheight)(

if(MapWindow ||!MapWindow) .closed)MapWindow.close();

MapWindow = window.open(src,'''',''width =''+ vwidth +'',hei ght =''+ vheight +'' ,top = 100,left = 10'');

}

-

Stephane Moriaux et son [moins] vieux Mac


ASM写道:

Roger Withnell写道:

我从当前窗口打开一个新窗口来显示地图。

可以显示几个不同大小的地图。该函数是给定地图的大小并相应调整窗口大小。

如果新窗口已经打开,新的地图大小将被忽略并且
新地图对于现有的新而言,它太小了窗口或者太大了,这是一个更严重的问题!

我试图通过关闭新窗口来解决这个问题,如果它已经打开
使用下面的代码,但无济于事。似乎typeof(MapWindow)
总是未定义的。该函数位于.js文件中。可以在.js文件中声明全局变量吗?

任何帮助都非常感谢。

var MapWindow;
函数OpenMapWindow(src ,vwidth,vheight)
{
if(typeof(MapWindow)!=" undefined"&& MapWindow.closed == false)
{
MapWindow.close( );
}
MapWindow = window.open(src," NewWindow"," width =" + vwidth +
",height =" + vheight +
",left = 100,top = 100,resizable = no,toolbar = no,scrollb ars = no,menubar = no");
MapWindow.focus();
}

var MapWindow = null;
函数OpenMapWindow(src,vwidth,vheight)(
if(MapWindow ||!MapWindow.closed)MapWindow.close();




哎呀?试试:


if(MapWindow&&!MapWindow.closed)MapWindow.close();

--------------- ^^

MapWindow = window.open(src,'''',''width =''+ vwidth +'', hei ght =''+ vheight +'',top = 100,le ft = 10'');

}




到OP:


你'如果没有

滚动条,会对不可调整大小的窗口的可用性感到抱怨。


试试这个参考:


< URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref76.html>


打开新窗口有很多可用性问题,应该是

尽可能避免。不要试图阻止用户重新调整窗口大小 - 大多数浏览器都会阻止你执行这个

无论如何。


你应该允许用户决定链接打开的位置 - 如果他们想要它在一个标签中打开它会怎样?


-

Rob


非常感谢,但如果窗户打开,仍然无法关闭窗户。


尝试了你的代码并稍微改了一下:


函数OpenMapWindow(src,vwidth,vheight)

{

if(MapWindow!= null)

{

if(MapWindow.closed == false)

{

MapWindow.close();

}

}

alert(MapWindow);

MapWindow = window .open(src,NewWindow,width =" + vwidth +,height =" + vheight +" ;, left = 100,top = 100,resizable = no,toolbar = no,scrollb ars = no,menubar = no");

MapWindow.focus(); < br $>
}


警报总是给MapWindow = null。


有什么想法吗?

ASM < ST ********************* @ wanadoo.fr.invalid>在消息新闻中写道:43 *********************** @ news.wanadoo.fr ...

Roger Withnell写道:

我从当前窗口打开一个新窗口来显示地图。

可以显示几个不同大小的地图。该函数给出了地图的大小并相应地调整了窗口大小。

如果新窗口已经打开,新的地图大小将被忽略并且新的
地图对于现有的新而言,它太小了窗口或太大,这是一个更严重的问题!

我试图通过关闭新窗口来解决这个问题,如果它已经打开使用
下面的代码,但无济于事。似乎typeof(MapWindow)始终未定义。该函数位于.js文件中。在.js文件中声明全局
变量是否可以?

任何帮助都非常感谢。

var MapWindow;
函数OpenMapWindow(src ,vwidth,vheight)
{
if(typeof(MapWindow)!=" undefined"&& MapWindow.closed == false)
{
MapWindow.close( );
}
MapWindow = window.open(src," NewWindow"," width =" + vwidth +",height =" +
vheight +
",left = 100,top = 100,resizable = no,toolbar = no,scrollb ars = no,menubar = no");
MapWindow.focus();
}



var MapWindow = null;
函数OpenMapWindow(src,vwidth,vheight)(
if(MapWindow ||!MapWindow.closed)MapWindow.close();
MapWindow = window.open(src,'''',''width =''+ vwidth +'',hei ght =''+ vheight +'',top = 100,left = 10'');
}

-
Stephane Moriaux et son [moins] vieux Mac



I open a new window from the current window to display maps.

Several maps of different sizes can be displayed. The function is given the
size of the map and adjusts the window size accordingly.

If a new window is already open, the new map sizes are ignored and the new
map is is either too small for the existing "new" window or too big, which
is a more serious problem!

I''ve tried to fix this by closing the new window if it is already open using
the code below, but to no avail. It seems the typeof(MapWindow) is always
undefined. The function is in a .js file. Is it all right to declare global
variables in a .js file?

Any help much appreciated.

var MapWindow;
function OpenMapWindow(src, vwidth, vheight)
{
if(typeof(MapWindow) != "undefined" && MapWindow.closed == false)
{
MapWindow.close();
}
MapWindow = window.open(src, "NewWindow", "width=" + vwidth + ",height=" +
vheight +
",left=100,top=100,resizable=no,toolbar=no,scrollb ars=no,menubar=no");
MapWindow.focus();
}

解决方案

Roger Withnell wrote:

I open a new window from the current window to display maps.

Several maps of different sizes can be displayed. The function is given the
size of the map and adjusts the window size accordingly.

If a new window is already open, the new map sizes are ignored and the new
map is is either too small for the existing "new" window or too big, which
is a more serious problem!

I''ve tried to fix this by closing the new window if it is already open using
the code below, but to no avail. It seems the typeof(MapWindow) is always
undefined. The function is in a .js file. Is it all right to declare global
variables in a .js file?

Any help much appreciated.

var MapWindow;
function OpenMapWindow(src, vwidth, vheight)
{
if(typeof(MapWindow) != "undefined" && MapWindow.closed == false)
{
MapWindow.close();
}
MapWindow = window.open(src, "NewWindow", "width=" + vwidth + ",height=" +
vheight +
",left=100,top=100,resizable=no,toolbar=no,scrollb ars=no,menubar=no");
MapWindow.focus();
}



var MapWindow=null;
function OpenMapWindow(src, vwidth, vheight) (
if(MapWindow || !MapWindow.closed) MapWindow.close();
MapWindow=window.open(src,'''',''width=''+vwidth+'',hei ght=''+vheight+'',top=100,left=10'');
}
--
Stephane Moriaux et son [moins] vieux Mac


ASM wrote:

Roger Withnell wrote:

I open a new window from the current window to display maps.

Several maps of different sizes can be displayed. The function is
given the size of the map and adjusts the window size accordingly.

If a new window is already open, the new map sizes are ignored and the
new map is is either too small for the existing "new" window or too
big, which is a more serious problem!

I''ve tried to fix this by closing the new window if it is already open
using the code below, but to no avail. It seems the typeof(MapWindow)
is always undefined. The function is in a .js file. Is it all right
to declare global variables in a .js file?

Any help much appreciated.

var MapWindow;
function OpenMapWindow(src, vwidth, vheight)
{
if(typeof(MapWindow) != "undefined" && MapWindow.closed == false)
{
MapWindow.close();
}
MapWindow = window.open(src, "NewWindow", "width=" + vwidth +
",height=" + vheight +
",left=100,top=100,resizable=no,toolbar=no,scrollb ars=no,menubar=no");
MapWindow.focus();
}

var MapWindow=null;
function OpenMapWindow(src, vwidth, vheight) (
if(MapWindow || !MapWindow.closed) MapWindow.close();



Ooops? Try:

if(MapWindow && !MapWindow.closed) MapWindow.close();
---------------^^
MapWindow=window.open(src,'''',''width=''+vwidth+'',hei ght=''+vheight+'',top=100,left=10'');

}



To the OP:

You''ll get gripes about the usability of non-resizable windows without
scrollbars.

Try this reference:

<URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref76.html>

There are many usability issues with opening new windows, it should be
avoided as much as possible. Do not try to prevent users from re-sizing
the window themselves - most browsers will stop you from enforcing this
anyway.

You should allow the user to decide where the link opens - what if they
want it to open in a tab instead?

--
Rob


Thanks for this but still can''t get it to close the window if it is open.

Tried your code and changed it slightly as follows:

function OpenMapWindow(src, vwidth, vheight)
{
if(MapWindow != null)
{
if(MapWindow.closed == false)
{
MapWindow.close();
}
}
alert(MapWindow);
MapWindow = window.open(src, "NewWindow", "width=" + vwidth + ",height=" + vheight + ",left=100,top=100,resizable=no,toolbar=no,scrollb ars=no,menubar=no");
MapWindow.focus();
}

The alert always gives MapWindow = null.

Any ideas?

"ASM" <st*********************@wanadoo.fr.invalid> wrote in message news:43***********************@news.wanadoo.fr...

Roger Withnell wrote:

I open a new window from the current window to display maps.

Several maps of different sizes can be displayed. The function is given the
size of the map and adjusts the window size accordingly.

If a new window is already open, the new map sizes are ignored and the new
map is is either too small for the existing "new" window or too big, which
is a more serious problem!

I''ve tried to fix this by closing the new window if it is already open using
the code below, but to no avail. It seems the typeof(MapWindow) is always
undefined. The function is in a .js file. Is it all right to declare global
variables in a .js file?

Any help much appreciated.

var MapWindow;
function OpenMapWindow(src, vwidth, vheight)
{
if(typeof(MapWindow) != "undefined" && MapWindow.closed == false)
{
MapWindow.close();
}
MapWindow = window.open(src, "NewWindow", "width=" + vwidth + ",height=" +
vheight +
",left=100,top=100,resizable=no,toolbar=no,scrollb ars=no,menubar=no");
MapWindow.focus();
}



var MapWindow=null;
function OpenMapWindow(src, vwidth, vheight) (
if(MapWindow || !MapWindow.closed) MapWindow.close();
MapWindow=window.open(src,'''',''width=''+vwidth+'',hei ght=''+vheight+'',top=100,left=10'');
}


--
Stephane Moriaux et son [moins] vieux Mac



这篇关于如果窗口已经打开,请关闭它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆