Click to See Complete Forum and Search --> : Please help with a popup window focus and position problem


chuckkidd
07-03-2005, 01:15 AM
I have a page with multiple images on it.I need to be able to click on an image and have a popup window load a url and center it on the screen. it must retain focus so i can click another image on the main page and load a different url into the popup and have it come back to the front (get focus).

I have tried to write it myself and almost got it. the problem i have is:

if i click an image the popup comes to the front ok but is not centered, i can click another image and it comes back to the front ok. However if I close the popup and then click on another image to open the popup again i get a script error. Only happens when i manually close the popup with the X in the corner.

this is a link to the page withthe images and code.

http://www.lhfcorp.com/wood/rightlaminate.html

can someone please help fix it. I am totally lost as to what to do.

Thanks a bunch...Chuck Kidd

buntine
07-03-2005, 01:22 AM
Wrong forum. See the forum description.

HaganeNoKokoro
07-03-2005, 01:36 AM
var left=(screen.availWidth-750)/2;
var top=(screen.availHeight-400)/2;
function showit(txt) {
window1 = window.open(txt,"window1","width=750,height=400,left="+left+",top="+top+",toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
window1.focus();
return false;
}Should do the trick. That is, it should always open links in the same popup, and always bring that popup into focus.

Oh, your links should be like this:<a href="http://www.example.com" onclick="return showit(this.href);">Link contents</a>The onclick is returning false means the main window won't go anywhere when you click the link, and if a user has javascript disabled, the link will just take them where they need to go in the current window.

EDIT - added code to center the popup.

chuckkidd
07-03-2005, 07:44 AM
one last question..when i close the window with the link images can it check for and close the popup so it dosn't hang around in the bakground?


thanks again you have been a blessing today

Chuck

HaganeNoKokoro
07-03-2005, 12:59 PM
Add the blue partsvar left=(screen.availWidth-750)/2;
var top=(screen.availHeight-400)/2;
var window1=null;
function showit(txt) {
window1 = window.open(txt,"window1","width=750,height=400,left="+left+",top="+top+",toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
window1.focus();
return false;
}

window.onunload=function() {
if(window1!=null) {
window1.close();
}
}