1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

javascript reload parent window

Discussion in 'Web Design and Development (archive)' started by lauras2004, Jan 27, 2004.

  1. macrumors newbie

    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()">


  2. macrumors member

    Here is an example... this is your form page, I called it popupform.html
    <script language="JavaScript"><!--
    var windowReference;
    function openPopup() {
      windowReference = window.open('popupform2.html','windowName');
      if (!windowReference.opener)
        windowReference.opener = self;
    <a href="javascript:openPopup();">Open Pop-up</a>
    <form method="GET" name="formName" onSubmit="alert('submit triggered')">
    <input type="hidden" name="example" value="foo">
    and this is the pop-up window, I called it popupform2.html

    <input type="button" value="Submit" onClick="opener.document.formName.submit()">
  3. macrumors newbie

    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!

  4. macrumors 603


    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
    <a href="somepage.htm" target="_blank">
    <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.
  5. macrumors 603


    And to reload the parent window from the popup you can include this code in the popup in the appropriate location.


    Good luck.
  6. macrumors newbie

    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.

Share This Page