How to close all windows in a web application?

G

Guest

Hi I have a web application that has a log off selection, just redirects the
browser to a form with a label displaying you are loging off. In part of the
application I open a new window and was wondering if there is a way to close
all windows associated with the web application when the user selects the log
off selection?
Thanks.
 
L

Lau Lei Cheong

Just create an array of variable that holds the handle returned by your
calls to window.open(). Then use it to close accordingly.

e.g.:
function openwin() {
fhandle = window.open("popup.aspx");
}

function closewin() {
fhandle.close();
}
 
G

Guest

Thanks for the information, just wondering if you know what event to use if
aparent different aspx file is loaded into the web window, say with a
hyperlink as I want to close another window when this takes place?

Lau Lei Cheong said:
Just create an array of variable that holds the handle returned by your
calls to window.open(). Then use it to close accordingly.

e.g.:
function openwin() {
fhandle = window.open("popup.aspx");
}

function closewin() {
fhandle.close();
}
 
V

Vik

How can I get a handle of a browser window which is opened by a user through
the browser menu?

Thanks.

Lau Lei Cheong said:
Just create an array of variable that holds the handle returned by your
calls to window.open(). Then use it to close accordingly.

e.g.:
function openwin() {
fhandle = window.open("popup.aspx");
}

function closewin() {
fhandle.close();
}

Paul said:
Hi I have a web application that has a log off selection, just redirects the
browser to a form with a label displaying you are loging off. In part
of
the
application I open a new window and was wondering if there is a way to close
all windows associated with the web application when the user selects
the
 
G

Guest

I set up this below as lau suggested, and it the functions seem to work. So
the handle for the window that displays control_numifno.aspx is win_usr.
<script language="javascript">
function openwin(){
win_usr=window.open ("control_numinfo.aspx")
}
function closewin(){
win_usr.close();
}

Vik said:
How can I get a handle of a browser window which is opened by a user through
the browser menu?

Thanks.
 
L

Lau Lei Cheong

There are many ways. But the following is the one I preferred.

Add another server-side hidden textbox named "hid_func". The script for
opening window should set it to "hwndsav" then call click() on a server-side
button. When the server-side button handler see hid_func.Text == "hwndsav",
it knows it should save the handle and then set it's value to "" again. In
this fashion you can implement other client-server side interaction using
this single button.

Paul said:
Thanks for the information, just wondering if you know what event to use if
aparent different aspx file is loaded into the web window, say with a
hyperlink as I want to close another window when this takes place?
 
V

Vik

In your example, the new window is open by code. What I need to know is a
handle for the new window opened by a user through the browser menu
File->New->Window.
 
L

Lau Lei Cheong

The fact is: You simply can't alter things that is not within your current
scope of DOM model.

Since the window opened using "File"->"New"->"Window" is not opened by your
script, you has no reference/handle/access to it and cannot close it. By
enabling the script to do so is in fact violating the security measure of
the browser. (Since maybe one window is opening pages in internet zone and
another is opening pages in local zone, if I can manipulate other window
then maybe I'm possible to execute malicious ActiveX controls on the client.
The best way to prevent this is to block access from your script to it.)

For example, you're assured when you checking your email through webmail,
the other pages you're visiting cannot see the content of your email. (Or is
it so? Maybe someone have trick to get through it. Also, I can't remember
whether cookies can be shared over windows opened by this method.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top