Solved

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

Posted on 1997-11-12
9
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to make google charts responsive 4 54
ModalPopup  question 22 39
Use Mid in Html 6 23
make control visible based off other control value 7 24
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

730 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