PDA

View Full Version : Answer me plz its urgent...


sonibhavinh
06-28-2002, 10:34 AM
I want to close two browser windows at the same time by clicking on one link in any of the two pages is it possible.

bcarl314
06-28-2002, 11:59 AM
If you opened the windows from a script with the "window.open()" method and named each window, you can close them from the parent window with...
<script>
<!--
function closeWin() {
window.close(myWin1);//myWin1 is the name of the 1st window
window.close(myWin2);//myWin2 is the name of the 2nd window
}
//-->
</script>
then in your html use this for the link.
<a href="javascript:closeWin()">Close both windows</a>

At least it should work, you may need quotes around the names, can't remember.

sonibhavinh
06-28-2002, 01:15 PM
The code u gave is working fine when there are two windows which were opened by using the window.open(). But i want to close the two windows in which one is opened in the browser(parent window) and in that i have used the window.open() to open an new window. Now i want to close this both windows from the child window. Is it possible plz help me...

bcarl314
06-28-2002, 01:25 PM
This is a shot in the dark, but it might work.

From the granchild window try this...

parent.window.parent.window.close()
parent.window.close();

I think if you try to close the original parent (grandparent) window an alert box pops up though.

sonibhavinh
06-28-2002, 01:36 PM
No it is not working. Do you have any other idea.

joh6nn
06-28-2002, 01:47 PM
it isn't possible to close the main browser window using javascript. it constitutes a security risk, and an invasion of privacy, so there are controls that prevent it from happening.

andrewweb
06-28-2002, 04:26 PM
I main window opens window 1, and window 1 opens window 2, and you want main window to close both, then define a function in window 1 code that closes window 2.

Then in main window, do:

window1.close_window2_function();
window1.close()

adios
06-28-2002, 08:17 PM
<input type="button" value="Close All"
onclick="if(opener&!opener.closed)opener.close();self.close()">

This closes both pop-ups...

bazz
04-25-2003, 06:36 PM
I found this whilst searching for a script and thought it better to follow in than open a new thread.

My site operates mainly from the first broser window that opens. Through necessity though, I do have a pop-up for more specific content.

What I need is to be able to load a page from a hyperlink in the pop-up in the main window whilst at the same time closing the pop-up.

be getle with me I'm only a learner :thumbsup:

thanks

Roy Sinclair
04-25-2003, 10:00 PM
What I need is to be able to load a page from a hyperlink in the pop-up in the main window whilst at the same time closing the pop-up.


This should do the trick:


<a href="whereever..." onclick="window.opener.location.href=this.href; window.close; return false;">A link</a>

bazz
04-26-2003, 12:41 AM
Thanks but....

This is the link as copied from my page (having firstly inserted what you suggested.

<a class="standardlink" href="../../folder/document.htm" onclick="window.opener.location.href=this.href; window.close; return false;">

It does make the main window change to the desired display but it doesnt close the smaller window. Have I entered the line wrongly or wot?

thanks again.

Bazz

cheesebagpipe
04-26-2003, 03:09 AM
Another possibility: name the 'main' window:

<script type="text/javascript" language="javascript">

self.name = 'bazzWin';

</script>

(in all your pages). Then:

<a class="standardlink" href="../../folder/document.htm" target="bazzWin" onclick="if(opener&&!opener.closed)opener.location=this.href;self.close();return false;">

...in the pop-up.

Roy Sinclair
04-28-2003, 03:35 PM
Cheesebagpipe saw the problem, I left out the () on the window.close() call.

cheesebagpipe
04-28-2003, 03:39 PM
Hey Roy...shouldn't that be...

Give me ambivalence or give me something else

:confused:

Roy Sinclair
04-28-2003, 04:56 PM
Originally posted by cheesebagpipe
Hey Roy...shouldn't that be...

Give me ambivalence or give me something else

:confused:

Naw, ambivalence is an attitide you adopt while ambiguity is something you can receive.

bazz
04-28-2003, 05:32 PM
who cares anyway? :D

Once again guys, thanks for the help. They both work a treat.