Solved

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

Posted on 2009-05-13
5
1,882 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JS library vs Js framework 11 23
Bootstrap question 4 30
selected value 16 26
disable open new tab with right mouse click in <a> tag 3 19
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

749 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