PDA

View Full Version : Javascript close window +


jonirvine
06-25-2001, 03:55 PM
Hi all,

If someone knows could you please explain how to do the following:

I'm making a guestbook for somebody and they would like the 'sign the guestbook' page to be a pop up window. OK, this is fine but is it possible, using javascript that once they've filled in the guestbook and hit submit.... the pop up is closed automatically?

Cheers in advance guys and gals,

Jon

kdjoergensen
06-25-2001, 04:52 PM
From a script in the popup window you can close it as:
self.close();

however, you have to watch out if you use a submit command (e.g. form.submit or <input type="submit">) as closing the window will cancel the submission, too.

I have two solutions:
1) you do the submitting from the main window,
2) you put in a pause before closing the window.

I don't like 2) above since you dont know how fast the users server connections are, etc and you risk either keeping the window open long after the submission has taken place or you end up cancelling the submission all together..

I prefer to go with 1) above.
What you would do is something like this:

<script language="javascript">
function sendIt(){
window.opener.sendNow();
}
</script>

Your "submit" button in the popup will now look like this:
<input type="button" value="submit" onclick="sendIt()">
E.g. really no longer a submit button but rather a regular click button with a function call...


A function, sendNow(), in the main window (the window which openeded the popup), will be called.
In the main window you first need to gather the info you need from the popup window and after that is done you can then stuff it into a hidden form in the main window and submit this one instead. All you need to do is then to close the popup from the main window.
e.g. if the popup was originally opended like this:

gBook = window.open("gues.html","guest");

then, you close the new window like this:
gBook.close();

Dr. Web
06-25-2001, 05:21 PM
Let me just add to KD's,

I usually put a thank you page in the pop-up window, and set it to timeout and close after like 3 seconds. this gives the user the impression that something is happening-and you could have the main window submit in the background while this is happening.

jonirvine
06-26-2001, 07:52 AM
A thank you page, good idea.

Could the thankyou page not close itself after say 3 seconds?

That way wouldn't the submission have already happened?

Say the form stays in the pop up and submits to page X.asp, once the form info was submitted this could automatically redirect to thanks.asp and then close.

Is this correct?

Jon

Dr. Web
06-26-2001, 05:15 PM
yes, but I thought the form itslef was on the main page, and the pop-up was a kind-of a information page.