Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

12 Experts available now in Live!

Get 1:1 Help Now