Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refocus on child window 1

Status
Not open for further replies.

sundog21

Technical User
Jul 17, 2001
8
0
0
US
I open a new browser window - named &quot;report&quot; from a list of links, then allow the user to minimize it, or go back to the parent window, and click another link. This hides the child window. If the user clicks another report link a new report opens in the &quot;report&quot; window (so only one popup window is open at a time). How do I set the focus on the child window (&quot;report&quot;) using an onClick in the link? I can set the focus by putting onLoad=&quot;focus()&quot; in the <body> tag of the report page but I would like to set the focus from the link in the parent page. Is that possible?
 
Let's say your popup window is a global [tt]popwin = window.open(blahblahblah)[/tt]. First you'll need a function:
[tt]
function refocus(){
if(popupwin){
if(!popupwin.closed&&popwin.document.readyState){
do{
}while(popupwin.document.readyState<>'loaded')
window.setTimeout('popupwin.focus()',10);
}
}
return(true);
}
[/tt]
... then in the anchor put [tt]onclick=&quot;refocus();&quot;[/tt]

Now, the only drawback to this method is that it has only been tested in IE5+ and will not work for NS4.
Paul Ellis
[hammer] I've been programming since you had to punch holes in cards to code. (Always remember, number your cards!)
 
...or have your links use a function to open the windows:
Code:
//  declare newWin here so you can test for it in openWin()
var newWin;

function openWin(sPage) {
  if (newWin && newWin.open && !newWin.closed) {
    newWin = window.open(sPage,&quot;newWindow&quot;,&quot;height=250,width=350&quot;);
  }
}

...and in your links:
<a href=&quot;#&quot; onclick=&quot;openWin('myPage.html');&quot;>
this should work for IE & NS

================================================================================================
 
Thanks for both of your suggestions: pellis and jemminger.
The approach you suggested, jemminger, got me on the right track. Thanks very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top