Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Cannot close popup window after submit

Reply
Thread Tools

Cannot close popup window after submit

 
 
Gabriella
Guest
Posts: n/a
 
      01-22-2007
Hi,

I have a popup window that opens from a page on my website.
This popup is a form with several fields.
Upon submit button it redirects to a server side ASP page which writes
all data to the DB.

I would like the popup to close immediately after the submit button is
clicked, and data is saved, (or cancel button) - but this does not
happen.
The popup window remains open, even though I have a "return false;"
after window.open in the onclick event.

What am I missing?

<a href="myurl.asp" onclick="window.open('myurl.asp',
'title','toolbar=no,width=700,height=600'); return false;">post a
note</a>;

Thanks, Gabi.

 
Reply With Quote
 
 
 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      01-22-2007
Hi,

Gabriella wrote:
> Hi,
>
> I have a popup window that opens from a page on my website.
> This popup is a form with several fields.
> Upon submit button it redirects to a server side ASP page which writes
> all data to the DB.
>
> I would like the popup to close immediately after the submit button is
> clicked, and data is saved, (or cancel button) - but this does not
> happen.
> The popup window remains open, even though I have a "return false;"
> after window.open in the onclick event.
>
> What am I missing?
>
> <a href="myurl.asp" onclick="window.open('myurl.asp',
> 'title','toolbar=no,width=700,height=600'); return false;">post a
> note</a>;
>
> Thanks, Gabi.


You misunderstood what "return false" does here. It only tells the
browser, that the "href" part of the link must not be executed after the
"onclick" event has been executed. If you don't return false, then the
browser will open the window, and then (when the script is finished), it
will navigate to the URL written in the HREF part.

If you want to close the pop-up after submitting the link, you can use
this code:

<input type="button" value="submit"
onclick="this.form.submit();top.close();" />

Alternatively, you can also use the onsubmit event of the form.

<form action="..."
onsubmit="top.close();">

....

</form>

Note also that pop-ups are rather not recommended, and you may consider
an inline floating DIV instead.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
 
Gabriella
Guest
Posts: n/a
 
      01-22-2007
Thanks a lot!!

Another question:
I want to refresh the opener page immediately after closing the popup.
How do I do that?

Why are popups not recommended?
Can you show me how to use an inline floading DIV instead?

Thanks again, Gabi.

 
Reply With Quote
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      01-23-2007
Hi,

Gabriella wrote:
> Thanks a lot!!
>
> Another question:
> I want to refresh the opener page immediately after closing the popup.
> How do I do that?


If you keep the popup, before you close the pop-up with self.close(),
you can call

opener.location.reload();

"opener" is a keyword with a reference to the opener window. The Window
object has a location property, which is an instance of the Location
object, which you can reload.


> Why are popups not recommended?


For many reasons, mostly explained here:
http://developer.mozilla.org/en/docs...dow.open.28.29

In short: You can never be sure that a popup will actually be displayed
(because of popup blockers), and it annoys users.

For the record, I still have a few apps using popups, but I am slowly
removing them when I work on these apps.

> Can you show me how to use an inline floading DIV instead?


You can use this kind of HTML/CSS code to position a DIV absolutely:

<div style="position: absolute;
top: 100px;
left: 200px;">

....

</div>

Additionally, you can play with the "display" property in the style to
show and hide the DIV, for example:

<div id="divForm"
style="position: absolute;
top: 100px;
left: 200px;
display: none;">

....

</div>

and then:

var nDiv = document.getElementById( "divForm" );
if ( nDiv
&& nDiv.style
&& nDiv.style.display )
{
nDiv.style.display = "block";
}

Note that since the DIV is inline (not a separate window), when you
submit the form, the whole page will be refreshed, which is what you
wanted from the start.

If you want to avoid refreshing the page, then you must resort to AJAX
to post your data to the server.


> Thanks again, Gabi.


HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      01-23-2007
Gabriella a écrit :
> Another question:
> I want to refresh the opener page immediately after closing the popup.
> How do I do that?


You must do it *before* to close the popup :

opener.location.reload();
or (depends what you want) :
opener.location = opener.location

Vedere gli esempi dati al vostro compatriota :
http://stephane.moriaux.perso.wanado...uc/tutticanti/

> Why are popups not recommended?


because most of surfer have anti-popups that could block yours.
Because Firefox by default open accepted popups in a tab (and this tab
is not allways automatically opened)

> Can you show me how to use an inline floading DIV instead?


ask to Google : tolltip
http://www.walterzorn.com/tooltip/tooltip_e.htm
very much heavy and hard to understand :
http://developer.yahoo.com/yui/container/tooltip/

ask to Google : modal dialog
http://sublog.subimage.com/articles/2006/01/01/subModal



--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
popup window close to submit opener window without 'causes validation' happening Matt Jensen ASP .Net 1 12-16-2005 03:16 PM
close current window using window.close() Shang Wenbin Javascript 10 09-02-2005 12:16 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com Javascript 2 01-01-2005 06:07 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM
Main > Popup > Popup > Close popup AND new URL in main? Jens Peter Hansen Javascript 7 06-19-2004 08:56 PM



Advertisments