Solved

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

Posted on 1997-11-12
9
351 Views
Last Modified: 2008-03-06
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.
0
Comment
Question by:Wiz_of_Oz
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 6

Expert Comment

by:Holger101497
ID: 1273547
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!
0
 
LVL 6

Expert Comment

by:tecbuilder
ID: 1273548
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.
0
 
LVL 6

Expert Comment

by:Holger101497
ID: 1273549
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...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:Wiz_of_Oz
ID: 1273550
the problem isn't the self.close(), but the form submission...

0
 
LVL 2

Author Comment

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

0
 
LVL 1

Expert Comment

by:twexperts
ID: 1273552
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)
0
 
LVL 6

Expert Comment

by:tecbuilder
ID: 1273553
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?
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1273554
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 :)




0
 
LVL 6

Accepted Solution

by:
Holger101497 earned 100 total points
ID: 1273555
I didn't post an answer right away because I couldn't be absolutely sure that it was the timing that caused his problem and wanted to keep the question open just in case somebody had had the exact same problem and knew that it was something else. Glad to hear that it helped!

About twexperts comment: Yes, that idea is not so bad either. The only problem is that his form has a TARGET to the main window (wouldn't make much sense to close it otherwise, would it? ;-) which doesn't have a reference to the other (smaller) window any more when the new page loads. He can always get a new one with ref=window.open ("","windowname") of course, but as long as this code works, it's probably easier. Even with slow connections, he doesn't need to receive the answer in that time. He only needs to give Netscape a short moment to send the data, because "technically", the onsubmit is executed before the form is submitted, so it's kind of a bug that Netscape 3 and IE still send the form after the window was supposed to close...

Good luck with your page!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hide cell in a table 2 27
How to format numbers and letters in nested lists 5 32
How to resize a div in html 3 36
HowTo set a global variable in javascript or jQuery 4 21
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question