Solved

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

Posted on 1997-11-12
9
345 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 2

Author Comment

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

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

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

0
 
LVL 1

Expert Comment

by:twexperts
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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 …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now