browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need JavaScript / Ajax / DHTML help?

Get answers from our community of JavaScript / Ajax / DHTML experts on BYTES! It's free.

post form to window opener

humbads
Guest
 
Posts: n/a
#1: Jul 23 '05
I am trying to get a popup window to work for editing notes in my
application. Here's how I implemented it:

The original frame is called ORIGINALFRAME and contains a link like
this:

<a href="javascript:launchwin();">Edit Note</a>
function launchwin() {
// ... custom stuff
newNoteWindow = window.open(strURL,'NoteWindow',strOptions);
if(newNoteWindow.opener == null) {
newNoteWindow.opener = self;
}
if (window.focus) {
newNoteWindow.focus();
}
}

In the resulting pop-up window, I have a POST form whose onSubmit
handler contains these lines:

document.forms[0].target=window.opener.name; // becomes ORIGINALFRAME
document.forms[0].submit();
window.close();

I am passing the URL of the ORIGINALFRAME as a query string parameter
to the pop-up window. In the page that handles the form submission, it
reads this parameter and redirects to it after processing the form.
This way, the original frame appears to reload, and it only reloads
after the form is completely processed.

The implementation doesn't work in either IE or Firefox when there is
more than one original frame with the same name in multiple windows.
In Firefox, the post is directed to the first original frame, while in
IE, it doesn't seem to do anything.

The POST form is in the pop-up window. Does anyone know how to set its
target to the opener, reliably?




humbads
Guest
 
Posts: n/a
#2: Jul 23 '05

re: post form to window opener


To solve this, instead of changing the target of the form to the
opener, I could instead post directly to the self window (the pop-up
window). Then I use some javascript in the form response to refresh
the opener and close the window, like this:

' Form Handler (In ASP) - Show a javascript page to
' refresh the opener and close the pop-up window
%><html><head>
<script type="text/javascript">
function CloseWindow() {
window.opener.location.href='<%=RedirectURL%>';
window.close();
}
</script>
</head><body
onload="CloseWindow();"></body></html><%
Response.End

But this is not the most elegant solution...

Closed Thread