Solved

Refresh parent window from child window while retaining focus on child window

Posted on 2009-05-13
5
1,847 Views
Last Modified: 2013-11-19
The issue I'm facing is as follows:
1. I have a browser window - say Window A - open.
2. On clicking a link this window opens a popup window.
3. After opening the popup I need to refresh the parent page (which has a pointer to the child popup window).
4. After refreshing the parent page I want to give the focus back to the child page. But since I refreshed the parent page, I no longer have a pointer to the child window.

Is there any way I can get around this problem.
0
Comment
Question by:Seeker2468
  • 3
5 Comments
 
LVL 1

Assisted Solution

by:ckontz
ckontz earned 20 total points
ID: 24382099
The child can ask the parent to refresh and the child will still have reference to itself.  Reloading the parent doesn't change focus to it.  If there is code in the parent that gives it focus, then call it after you reload the parent() - maybe after a short delay for the reload to finish).

The following function can be called multiple times from the child window:

function refreshParent()
{
  window.opener.location.reload(true);
  // if the parent sets focus to itself, then add the next line
  setTimeout('focus();',5000);  // gives focus back to this window after 5 seconds
}
0
 

Author Comment

by:Seeker2468
ID: 24386002
This sounds good, but there is a twist to the story :) I can't change code on the child popup I am calling. Its sort of in a different module so to speak, and is called by other pages which dont require the behavior that my parent page requires - i.e. to refresh itself.

So the only option for me is to launch the child, refresh myself, and then somehow set the focus to the child window. I'm not quite familiar with javascript, so not sure how possible this is.
0
 

Author Comment

by:Seeker2468
ID: 24386036
More specifically if I retain the name of the child window, is there a way when the page refreshes itself to find all child windows with a particular name? Something along these lines.
0
 
LVL 12

Assisted Solution

by:Chad Haney
Chad Haney earned 30 total points
ID: 24399765
Try using something like this.

Because of the way the javascript calls are made it will open the child, then the child will end up calling the parent part of the script due to the focus change.
<a href="javascript:window.open('http://www.google.com','childWindow');parent.window.location.reload();">link</a>

Open in new window

0
 

Accepted Solution

by:
Seeker2468 earned 0 total points
ID: 24403902
dachusa, I havent tried this code. will try and see if it does the job; though I think I'd still have the issue of child window loosing focus, at least in IE (step 4 in the problem).

Just FYI, I did solve my problem another way. I opened the popup as follows

window.open("http://...","popupname",features);
document.theForm.linkName.value = "http://...";//linkName is a request parameter
reload();

onload()=function { window.open(document.theForm.linkName.value,"popupname");}
//This code essentially gives focus back to the already open child window once the parent window is reloaded.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now