By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

beginner: how to close a pop up window before opening an other pop up

P: n/a
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>
================================================== ===
Sep 15 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
ASM
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.


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
Sep 15 '05 #2

P: n/a
thanks for your help, it is now working as it should

blablavatksy
Sep 15 '05 #3

P: n/a

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);
}


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


Sep 15 '05 #4

P: n/a

"Madame Blablavatsky" <Bl**********@hotmail.com> wrote in message
news:43***********************@nova.planet.nl...

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);
}


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?


or.
Sep 15 '05 #5

P: n/a

"Zoe Brown" <zo***********@N-O-S-P-A-A-Mtesco.net> wrote in message
news:NI*****************@newsfe3-gui.ntli.net...

"Madame Blablavatsky" <Bl**********@hotmail.com> wrote in message
news:43***********************@nova.planet.nl...

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);
}
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?


or.


oops my mistake..

Sep 15 '05 #6

P: n/a
ASM
Madame Blablavatsky wrote:
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);
}

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.


so ... now you know why they are
I can knowwhere find the meaning of it.


! want to say 'no'

experiment :

<html>
<script>
var asm = true;
alert( !asm ) ; // --> false
alert( !!asm ); // --> true
</script>
</html>

--
Stephane Moriaux et son [moins] vieux Mac
Sep 15 '05 #7

P: n/a
ASM
Zoe Brown wrote:
"Madame Blablavatsky" <Bl**********@hotmail.com> wrote in message
news:43***********************@nova.planet.nl...
what is the meaning of the double exclamation mark?

or.


not at all

--> 'or' = ||
--> 'and' = &

and ! (exclamation mark)

--> 'no' = !
--
Stephane Moriaux et son [moins] vieux Mac
Sep 15 '05 #8

P: n/a
<html>
<script>
var asm = true;
alert( !asm ) ; // --> false
alert( !!asm ); // --> true
</script>
</html>


thanks for your help and explanation, it is clear to me now.

blablavatsky
Sep 15 '05 #9

P: n/a
So, semantically, it's useless, right? I'm not missing anything here?
It just means 'not not', which cancels itself out?

-Brendan

Sep 16 '05 #10

P: n/a
JRS: In article <11*********************@g47g2000cwa.googlegroups. com>,
dated Fri, 16 Sep 2005 06:48:03, seen in news:comp.lang.javascript,
Donius <ra**************@gmail.com> posted :
So, semantically, it's useless, right? I'm not missing anything here?
It just means 'not not', which cancels itself out?


No. Yes. Sort of.

It returns a Boolean, whatever it may have been given; and a Boolean is
the right way to represent a two-way yes/no-type quantity. It does so
whether it is given on its right a number, string, function name,
undefined, NaN, +-infinity, and UTC&A&A.

However, in the context
if (win || !!win.closed) win.close();
in which it was introduced in this thread, ISTM superfluous; win.closed
should already be Boolean, and, if it were not, the context would coerce
it - its author is already relying on the context to coerce a function
reference or undefined to Boolean.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.