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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maintain focus in popup window?

Status
Not open for further replies.

sbueffel

Technical User
May 4, 2002
3
US
I am using the following function on my website:

function popup(link, w, h) {
popupWin = window.open(link,'remote','width=' + w + ',height='+ h)
}

and then use this link to show full size images with this href:

javascript:popup('image_location', 500, 380);

When I follow a link for the first time a popup opens like I want. If you then click on another thumbnail, it replaces the image in the popup with the one just clicked, but the focus returns to the main window, putting the popup in the back. So you either have to click on the popup to regain focus or you have to close the popup before clicking on the next thumbnail. I would like to change the code so that the popup window retains the focus when another thumbnail is clicked. The focus does not have to be on the popup the whole time, but just regain the focus after a link is clicked that puts an image in that popup. How do I go about accomplishing this? Thank you very much.

Sample problem is at
Scott.
 
This will do what you want, and is online with several sites we designed and host currently.

var popupWin;

function popup(photoname, carname)
{
if (popupWin != null) {if (!popupWin.closed) popupWin.close();}

//the rest of your code here

}
 
Thanks for your help. You'll have to forgive my incompetence when it comes to scripting...I took that code and added it to one of my pages, but it didn't change anything. So I did my best manipulate the code to do what I thought might make it work. All I did was break my original function.

So I could use a little more help. My knowledge with the function I am using involves knowing that I put it in the head of my document. I know nothing more (well, at least in terms of JS). Am I supposed to be able to take your code verbatim and put it above mine and all should be okey-dokey? Or are there some variables or values I need to adjust? Thanks again.

Scott.
 
Sorry about not trimming things out from the original page

var popupWin;

function popup(link, w, h)
{
if (popupWin != null) {if (!popupWin.closed) popupWin.close();}

popupWin = window.open(link,'remote','width=' + w + ',height='+ h)

}
 
Thank you, Trollacious. Works perfectly now. Base on what I am seeing, the code actually checks to see if the window is open, and if so closes it before opening a new one. So it really isn't changing the focus back to the popup window, because it is a different one. Is this because it is too hard or can't be done to move the focus back to the original popup? This isn't a complaint, just learning here. Thanks again.

Scott.
 
You're correct in your conclusions about how this work. IE and Netscape handle closed windows differently, and that's why there are the 2 tests first to make sure it's closed. I've found this is the easiest way to bring it back into focus, and if you're using something like a graphic that's a different size than before, this gives you a clean window to work with. If you don't close it and you load a graphic with different dimensions than the first one, it can look really strange and distorted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top