Groups | Blog | Home
all groups > dotnet jscript > november 2004 >

dotnet jscript : Easy question I think


Paul
11/22/2004 5:09:06 PM
Hi I have an easy question I think. I have a web window file1.aspx that has
a hyperlink target as blank to it opens a new window with a url of
file2.aspx. When the user navigates away from file1.aspx I want to be able
to close file2.aspx, so in the body tag I tried,
<body
onUnload event = "file2.aspx.close"

which is not correct. thanks Paul.
--
Paul G
Simone Massaro
12/2/2004 10:53:13 AM
You have to do it trough clientside javascript because the window has been
opened on the client side and the server doesn't know anything about it.
Isntead of using an hypelink to open the second window use a jscript to open
a new instance of the browser and store a pointer to this instance into a
global variable.
Later on when the first page is closed use the pointer that to the second
instance to send the close message.
--
Simone

sshimla NO[at]SPAM viateks-dot-com.no-spam.invalid
12/9/2004 6:56:43 AM
Hi,

You can try this:
<BODY onunload="window.opener.close()">

It works on window.open() and also on a hyperlink where target=_BLANK

In general (pending on browser security) you can do various operations
on windon.opener as if it was the current window.

You can submit a form, change a control value and even read opener
window's data into the child (newly opened) one.

The reason security is limiting that is so a page opened by a
different site or something wont read data you are about to post on
the parent one (i.e. credit card number)...

2 things:
1) A more elegant way is using target names instead of just BLANK so
you can access siblings similarly to frames
2) If your parent window was opened by the user (open browser and go
to parent page) then it will show a confirmation message before
closing the parent (so you don't go off closing windows that the user
wanted open in the first place...)

Hope this helps...

*-----------------------*
Posted at:
www.GroupSrv.com
AddThis Social Bookmark Button