Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-05-13
5
Medium Priority
?
2,005 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Assisted Solution

by:ckontz
ckontz earned 80 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 120 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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

604 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