PDA

Click to See Complete Forum and Search --> : JavaScript: Position popup window


RobDog888
Jul 16th, 2004, 02:52 PM
I want to position a popup window in the center of the browser
window not the center of the screen. This is what I am using to
open the window and the left property works and the top
property doesn't for centering in the screen. So how do I get it to
center in the browser window and if not, how to get the top
property to center correctly?
function Zoom(imgName,imgWidth,imgHeight,oPosL,oPosT) {
//Center window from center of screen
//oPosL and oPosT are center of screen - (screen.width/2) etc.
var TempLeft = (imgWidth / 2);
var TempTop = (imgHeight / 2);
var PosL = (oPosL - TempLeft);
var PosT = (oPosT - TempTop);
zoomWindow = window.open '', 'zoomWin', 'width='+imgWidth+',height='+imgHeight
+'top='+PosT+',left='+PosL+',toolbar=0,menubar=0,location=0,scrollbars=0')
zoomWindow.window.resizeTo(imgWidth, imgHeight+30);
}
Thanks for any assistance.

RobDog888
Jul 16th, 2004, 03:05 PM
!@#$!@$, I was missing a @#*$! comma.
So it now centers in the screen, but can we get it to center in the
browser (in case the user is not running the browser in full
screen mode)?
function Zoom(imgName,imgWidth,imgHeight,oPosL,oPosT) {
//Center window from center of screen
//oPosL and oPosT are center of screen - (screen.width/2) etc.
var TempLeft = (imgWidth / 2);
var TempTop = (imgHeight / 2);
var PosL = (oPosL - TempLeft);
var PosT = (oPosT - TempTop);
zoomWindow = window.open '', 'zoomWin', 'width='+imgWidth+',height='+imgHeight
+',top='+PosT+',left='+PosL+',toolbar=0,menubar=0,location=0,scrollbars=0')
zoomWindow.window.resizeTo(imgWidth, imgHeight+30);
}

RobDog888
Jul 19th, 2004, 02:01 PM
*BUMP*

Ecniv
Jul 20th, 2004, 04:20 AM
Send the centre of the window instead.

So how do you get the full screen width / height ?
Try window.Width and window.Height or something from the calling window... instead of the screen width/height.

You may have to account for resolution stil tho?


Vince

RobDog888
Jul 20th, 2004, 11:35 AM
screen.width/2 and screen.height/2 gives you the center of the screen.

window.width returns as "undefined".

How and where should I be using it. I tried in the htm and the .js file.

:confused:

brown monkey
Jul 23rd, 2004, 04:50 AM
this mate?

<html>
<head>
<style>
input{
font:9pt arial;
}
</style>
<script language="javascript">
function f(){
windowScreenX=window.screenX;
windowScreenY=window.screenY;
width=300;
height=160;
top=windowScreenY+(window.innerHeight/2);
left=windowScreenX+(window.innerWidth/2)-width/2;

s='width=' +width+ ',height=' +height+ ',top=' +top+ ',left=' +left;
window.open('sample.html','sample',s);
}
</script>
</head>
<body>
<input type=button value='click me' onclick='f()'>
</body>
</html>

RobDog888
Jul 24th, 2004, 01:26 AM
Looks promissing! When I get some time from remodeling our
house this week, I will try it and let you know.

Thanks.

RobDog888
Jul 30th, 2004, 03:14 PM
window.innerWidth keeps coming up as undefined?
My code is in an external js file, if that matters?

Thanks.

Acidic
Jul 30th, 2004, 03:18 PM
try document.innerHTML
don't know if that even works
maybe document.body.innerHTML
maybe put everything in a div called wee
thn do document.wee.innerHTML

RobDog888
Jul 31st, 2004, 10:23 PM
But this is on an external js file. Guess I will have to settle for
center screen only, for now. :(

Acidic
Aug 1st, 2004, 08:49 AM
it being an external file shouldn't matter.

RobDog888
Aug 4th, 2004, 06:01 PM
Ok, thanks. I will do more testing.