Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lauras2004

macrumors newbie
Original poster
Jan 27, 2004
3
0
Hi all,

I'm trying to submit a form from a popup window and when the user hits the "Submit" button, the parent window should reload.

It works on Windows IE and Netscape, and Netscape 7 on the mac, but so far I can't get it working on IE5 for the mac.

I'm using <onClick="parent.window.location.reload()">

Thanks!!

LauraS.
 
Here is an example... this is your form page, I called it popupform.html
Code:
<html>

<head>
<script language="JavaScript"><!--
var windowReference;

function openPopup() {
  windowReference = window.open('popupform2.html','windowName');
  if (!windowReference.opener)
    windowReference.opener = self;
}
//--></script>
</head>

<body>
<a href="javascript:openPopup();">Open Pop-up</a>
<form method="GET" name="formName" onSubmit="alert('submit triggered')">
<input type="hidden" name="example" value="foo">
</form>

</body>

</html>

and this is the pop-up window, I called it popupform2.html

Code:
<form>
<input type="button" value="Submit" onClick="opener.document.formName.submit()">
</form>
 
Ok, thanks for that ... I *kind of* see what's going on, although when I click the Submit button from the popup window, the first window does appear to reload but the "alert" isn't happening. That's not essential ... so I guess it's working so far.

Problem is, I'm not using javascript to open up the popup window. I'm just opening it using target="_blank". And somehow I think that's going to matter ...

Any (more) wisdom you can apply to this is much appreciated!

LauraS.
 
When cross-scripting windows, its always a good idea to "pop-up" new windows with a window.open() command. This will ensure that the javascript window hierachy is observed. This would allow you to access the "parent" window from the popup with the opener notation.

So a good idea may to be substitute
PHP:
<a href="somepage.htm" target="_blank">

with
PHP:
<a href="javascript:void(0);" onclick="javascript:window.open('somepage.htm', id); return false;">

Don't worry about the href as it will never be executed due to the return false in the onclick event. Also, that id is any string identifier you would like to use for your popup. That space in the word javascript should be removed (stupid code formatters :rolleyes: )

Finally, you may encounter security issues if you try to control an opener window if the popup and the opener do not belong to the same domain name.
 
Thanks for the info. Unfortunately because of standards set by my company, we're not using javascript to open popup windows at all -- only target="_blank".

It's worth noting that even though I didn't use javascript to open the new window, window.opener.location.reload() DOES work on the Windows platform. It even works with Netscape on the mac. It only breaks down when using mac / IE ...

Anyway, thanks again.

Laura S.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.