Link to home
Start Free TrialLog in
Avatar of Wiz_of_Oz
Wiz_of_Oz

asked on

OnSubmit="self.close()" doesn't work on NN4

I have the following problem, and I'll be 4ever in debt to the solver...
I have a window named "mainref" with the file index.asp loaded into, wich opens another
window with the function below:
windowref=window.open("target.asp","windowname","width=480,height=320")
and this works well;
in the target window I have a form defined as below:
<form name="name_form" action="index.asp" target="mainref"
OnSubmit="LEAVETHIS()">
I have to close the window "windowref" when the form is submitted, so i wrote the function
LEAVETHIS as following:
<script>
<!--
function LEAVETHIS()
{
self.close();
}
//-->
</script>
The self.close is executed after the form submission with MS IE 4.0 and Netscape 3.0, but
with Netscape 4.03 (the latest release i found...) the submission of the form isn't executed at
all....
Thanks to all those will reply this question.
Avatar of Holger101497
Holger101497

The submission isn't executed? It normally takes a short moment to contact the server etc. Your close might just be faster... (the onSubmit is executed BEFORE the form is submitted to allow validation).

Try this:
setTimeout("window.close()",3000);
That will close the window 3 seconds later. A shorter time might be enough, just experiment, but allow a little time extra if the computer or the network connection is slower somewhere else.

Let me know if that solved the problem. btw: If that was the reason, you have to admit that NN4 has the "more correct" behavior! The onsubmit is executed before your form is submitted and it closes the window. Tough for the form ;-)

Good luck!
I don't believe the self.close() or window.close() will work because the windowref window is not your current window.  Instead use windowref.close() in the script and it should work ok.  You also won't need the setTimeOut function.  I don't believe the speed of the machines is the issue.
hmm... maybe you should read the question before blocking it for everybody else?

1] windowref=window.open("target.asp","windowname","width=480,height=320")
in the *****target***** window I have a form defined as below:
<form name="name_form" action="index.asp" target="mainref" OnSubmit="LEAVETHIS()">
==> self.close() or window.close() are correct, the target window closes ITSELF (also indicated by closeTHIS)
2] The self.close is executed after the form submission with MS IE 4.0 and Netscape 3.0, but with Netscape 4.03 .... => If it works with two browsers (esp NN3), a wrong reference can hardly be the reason for it not working with a third browser.
3] The question says the FORM SUBMISSION isn't executed. The window DOES close...

Wiz_Of_OZ, let me know if the Timeout helped...
Avatar of Wiz_of_Oz

ASKER

the problem isn't the self.close(), but the form submission...

Thanks Holger...
I tried with a Timeout and magically everything works :)
4 ever in debt to u...

Glad to hear that Holger's suggestion worked, if you
are passing the form to a CGI, then you could also
have the CGI program whip out a quick page which
just closes the window, That way everytime the information
is submitted, even accross very slow networks, you are
gauranteed of success.

Robin (twexperts)
My apologies.  I would not have locked up the question if I did not believe I had an answer.  If you had the answer why didn't you lock the question up?
I see here some problems can be:
even if you set close after timeout
if connection is slow window can be closed BEFORE
submission occures in some browsers.
So data wouldn't submited.

In order to be sure data was submited you should
follow twexperts suggestion. ie close this window
when you receive CGI responce.
Just return in responce HTML containing

<html>
<body>
<script>
 window.close()
</script>
</body>
</html>


Again I think priority of this answer
may be not complete enough should be
twexperts :)




ASKER CERTIFIED SOLUTION
Avatar of Holger101497
Holger101497

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial