初学者:如何在打开其他弹出窗口之前关闭弹出窗口 [英] beginner: how to close a pop up window before opening an other pop up

查看:81
本文介绍了初学者:如何在打开其他弹出窗口之前关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我在页面上有几个链接。当一个人点击一个链接弹出一个窗口,然后打开一个图像。

当人们点击另一个链接我想要已经可用的弹出窗口

关闭之前
另一个弹出窗口打开。


i只是不能正确,我总是会收到一条错误消息:

行:23

字符:20

错误:对象不支持此属性或方法


带错误的行是:

vensters [x] .close();


这里是来源:

======================== source ====================

< html>

< head>


< script style =" text / javascript">

//''teller = 1'':没有弹出窗口打开;

//''teller = 0'':弹出窗口打开;

var beller;

teller = 0;


//带弹出窗口的数组;

var vensters = new Array(3 );

vensters [0] =" win1& ;;

vensters [1] =" win2";

vensters [2] =" win3";


函数openWindowPlaatje(num){

var x;


//如果弹出窗口已经打开,请在打开新弹出窗口之前将其关闭

up;

if(teller == 1){

for(x = 0; x< vensters.length; x ++){

if(vensters [x]!= num){

vensters [x] .close(); //此行给出错误信息;

}

}

}


//打开选中的弹出窗口;

if(num ==" win1"){

win1 = window.open(" plaatje1.html","", ''top = 250,left = 250,

width = 238,height = 255'');

teller = 1;

}


if(num ==" win2"){


win2 = window.open(" plaatje2.html"," "," top = 250,left = 250,width = 50,height = 50");

teller = 1;

}


if(num ==" win3"){


win3 = window.open(" plaatje3.html",""," top = 250,左= 250,宽= 150,高= 150')

;

出纳员= 1;

}


}


< / script>

< / head>


< body>


< a href =" javascript :openWindowPlaatje(''win1'')" > plaatje 1< / a>< br>

< a href =" javascript :openWindowPlaatje(''win2'')" > plaatje 2< / a>< br>

< a href =" javascript :openWindowPlaatje(''win3'')" > plaatje 3< / a>< br>


< / body>

< / html>

================================================== ===

hello,

i have a few links on a page. when one clicks a link an pop up window with
an image opens.
when people click an other link i want the already availible pop up window
to close before
the other pop up window opens.

i just can''t get it right, i always get an error message:
line: 23
char: 20
error: object doesn''t support this property or method

the line with the error is:
vensters[x].close();

here is the source:
======================== source ====================
<html>
<head>

<script style="text/javascript">
// ''teller=1'': no pop up window open;
// ''teller=0'': pop up window open;
var teller;
teller = 0;

// array with pop up windows;
var vensters = new Array(3);
vensters[0] = "win1";
vensters[1] = "win2";
vensters[2] = "win3";

function openWindowPlaatje(num) {
var x;

// if an pop up is already open, close it before opening a new pop
up;
if(teller == 1){
for(x = 0; x < vensters.length; x++){
if(vensters[x] != num ){
vensters[x].close(); // this line gives error message;
}
}
}

// open the selected pop up;
if(num=="win1"){
win1=window.open("plaatje1.html","",''top=250,left= 250,
width=238,height=255'');
teller = 1;
}

if(num=="win2"){

win2=window.open("plaatje2.html","","top=250,left= 250,width=50,height=50");
teller = 1;
}

if(num=="win3"){

win3=window.open("plaatje3.html","","top=250,left= 250,width=150,height=150")
;
teller = 1;
}

}

</script>
</head>

<body>

<a href="javascript: openWindowPlaatje(''win1'')" >plaatje 1</a><br>
<a href="javascript: openWindowPlaatje(''win2'')" >plaatje 2</a><br>
<a href="javascript: openWindowPlaatje(''win3'')" >plaatje 3</a><br>

</body>
</html>
================================================== ===

推荐答案

Madame Blablavatsky写道:
Madame Blablavatsky wrote:
你好,

我有几个页面上的链接。当一个人点击链接弹出窗口时会打开一个图像。
当人们点击其他链接时,我希望已经可用的弹出窗口
关闭之前
另一个弹出窗口窗口打开。
hello,

i have a few links on a page. when one clicks a link an pop up window with
an image opens.
when people click an other link i want the already availible pop up window
to close before
the other pop up window opens.




更正:

你没有验证弹出关闭是否存在


if(teller == 1){

for(x = 0; x< vensters.length; x ++){

if(vensters [x] != num&& vensters [x]&&!vensters [x] .closed){

vensters [x] .close(); //这一行给出了错误信息;

}

}

}

最好的方法是所有弹出窗口有相同的名字(这里:''赢'')


< html>

< head>

< script style =" text / javascript">


var win = false;


function pop(page,attrib){

//如果popup''win''存在或者没有关闭:关闭它

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

win = window.open(页面,'''',attrib);

}


函数openWindowPlaatje(num) {

if(num == 1)

pop(" plaatje1.html"," top = 250,left = 250,width = 238,he ight = 255);

if(num == 2)

pop(" plaatje2.html"," top = 250,left = 250,width = 50, hei ght = 50");

if(num == 3)

pop(" plaatje3.html"," top = 250,left = 250,width = 150,他ight = 150);

}


< / script>

< / head>


< body>


< a href =" plaatje1.html" target =" myWin"

onclick =" openWindowPlaatje(1); return false; > plaatje 1< / a>< br>

< a href =" plaatje2.html" target =" myWin"

onclick =" openWindowPlaatje(2); return false; > plaatje 2< / a>< br>

< a href =" plaatje3.html" target =" myWin"

onclick =" openWindowPlaatje(3); return false; > plaatje 3< / a>< br>


< / body>

< / html>


如果javascript被禁用,

访问者将在新的正常窗口中获得正确的页面


-

Stephane Moriaux et son [moins] vieux Mac



correction :
you didn''t verify if popup to close was existing

if(teller == 1){
for(x = 0; x < vensters.length; x++){
if(vensters[x] != num && vensters[x] && !vensters[x].closed){
vensters[x].close(); // this line gives error message;
}
}
}
the best way would be all popups have same name (here : ''win'')

<html>
<head>
<script style="text/javascript">

var win=false;

function pop(page,attrib) {
// if popup ''win'' exists or ins''t closed : close it
if(win || !!win.closed) win.close();
win = window.open(page,'''',attrib);
}

function openWindowPlaatje(num) {
if(num==1)
pop("plaatje1.html","top=250,left=250,width=238,he ight=255");
if(num==2)
pop("plaatje2.html","top=250,left=250,width=50,hei ght=50");
if(num==3)
pop("plaatje3.html","top=250,left=250,width=150,he ight=150");
}

</script>
</head>

<body>

<a href="plaatje1.html" target="myWin"
onclick="openWindowPlaatje(1); return false;" >plaatje 1</a><br>
<a href="plaatje2.html" target="myWin"
onclick="openWindowPlaatje(2); return false;" >plaatje 2</a><br>
<a href="plaatje3.html" target="myWin"
onclick="openWindowPlaatje(3); return false;" >plaatje 3</a><br>

</body>
</html>

if javascript is disabled,
visitor will get the right page in a new normal window

--
Stephane Moriaux et son [moins] vieux Mac


感谢您的帮助,它现在正在工作,它应该工作


blablavatksy
thanks for your help, it is now working as it should

blablavatksy



函数pop(page,attrib){
//如果弹出''win''存在或者ins 关闭它:关闭它
if(win || !! win.closed)win.close();
win = window.open(page,'''',attrib);
}

function pop(page,attrib) {
// if popup ''win'' exists or ins''t closed : close it
if(win || !!win.closed) win.close();
win = window.open(page,'''',attrib);
}




你好Stephane Moriaux,


我发现它是一个非常聪明的解决方案,但我还有一个问题:

双感叹号是什么意思?

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


起初我认为这是一个错误,但当我omi它给了它一个

错误信息。

我可以知道它找到它的含义。


谢谢




Hello Stephane Moriaux,

I find it a very clever solution but i still have one question:
what is the meaning of the double exclamation mark?
if(win || !!win.closed) win.close();

At first I thought it to be a mistake, but when I omitted it, it gave an
error message.
I can knowwhere find the meaning of it.

thanks



这篇关于初学者:如何在打开其他弹出窗口之前关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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