Results 1 to 6 of 6

Thread: Javascript - Refresh Parent Window?

  1. #1
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Question Javascript - Refresh Parent Window?

    Hi

    I have an HTML page (index.html) and a link in it. Clicking on that link opens a javascript Popup (popup.html). There is a small form on the popup window. Now when someone submits the form in that popup.html page, the index.html should refresh automatically.

    Anyone knows how to do this?


    Please help me.


    Thanx

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    On popup.html:
    Code:
    <a href="#" onclick="window.opener.document.location.reload(true);return false;">Refresh Parent</a>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    Question:

    Can this be used after the form is submitted? Or this needs to a click event to operate?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,191 Times in 3,155 Posts
    Blog Entries
    12

    Default

    You can use the form's submission:

    Code:
    <form action="whatever" onsubmit="window.opener.location.reload();">
    If the opening window already has a name, you may even target the form to that window, loading whatever page (the form's action attribute) you like into that window. Doing so will send the form's post or get data to that page. It can even be the same page that was in that window, in which case it would be like a refresh.

    The only problem with any of this though is that without javascript enabled, unless you use frames or iframe(s), there is no way to be sure of a way to target a particular window. Even then (with some sort of frame, and/or using javascript), your imagined target may have been closed by the user before you get a chance to reload it or whatever.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have problem here. Popup window is opened from one frame. On closing the popup window I want to refresh/reload whole page (not just frame from which popup window was opened). How do I do that?

    I've put:
    function closeReload() {
    opener.location.reload();
    self.close();
    }
    but it relaods only one frame, not the whole page.

    The page that is supposed to be reloaded is index.html.
    I have 3 frames in total. Should I somehow reload each of them. I've tried putting this:


    function closeReload() {
    top.document.frames[0].location.reload();
    top.document.frames[1].location.reload();
    top.document.frames[2].location.reload();
    self.close();
    }

    but it's not working

    Anyone?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,191 Times in 3,155 Posts
    Blog Entries
    12

    Default

    The frameset and the pop up page must be on the same domain:

    Code:
    window.opener.top.location.reload();
    However, what do you expect to happen? This will refresh the opening page's top frameset. What this means is that in FF the pages currently in that frameset will reload. In IE they will go back to their starting pages.

    If you want to always reset the pages in the frameset to their starting pages, you would have to specify the location (still requires frameset and pop up page on the same domain):

    Code:
    window.opener.top.location = 'name_of_the_frameset.htm';
    If the path to the frameset is different than the path of the pop up, it should be given along with the filename.

    To get them to always just refresh their current pages, even in IE - that's a little tricky:

    Code:
    function refreshOpenerTopFrameset(){
    var f = window.opener.top.frames;
    for (var i = f.length - 1; i > -1; --i)
    f[i].location.reload();
    }
    And that will only work if all the pages in the frameset, the pop up page, and the frameset page are on the same domain.
    Last edited by jscheuer1; 08-15-2008 at 03:36 PM. Reason: simplify after testing - later, add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •