PDA

View Full Version : Specifying a window's opening location


Walt
07-16-2002, 07:58 PM
Hello

I need to specify the location and size of a window at opening.

I suppose I need to write a function, then put onLoad("function_name") in the BODY tag.

I've played around using
self.moveTo(x,y), self.resizeTo(x,y), window.moveTo(x,y), window.resizeTo(x,y) but haven't even come close to finding anything that works.

If anyone can lend some guidence, I will be very grateful.

Also, is it possible to assign a width to the window which exceeds the displayable area of the screen?

Thanks in advance for all assistance.

Walt

Jeepers
07-16-2002, 08:21 PM
I use this script to pop up a window centralised within the existing browser window. I have altered it from something that somebody else posted here so I am sure that it can be altered to achieve what you want.

function PopUp(){
var scrHeight=220;
var scrWidth=540;
if (navigator.appName=="Netscape")
{scrHeight=scrHeight+10;
placementx=((window.innerWidth-scrWidth)/2)+window.screenX;
placementy=((window.innerHeight-scrHeight)/2)+window.screenY+95;
window.open("info.html","","titlebar='no',screenX="+placementx+",screenY="+placementy+",width="+scrWidth+",height="+scrHeight)
}
else
{placementx=((document.body.clientWidth-scrWidth)/2)+window.screenLeft;
placementy=((document.body.clientHeight-scrHeight)/2)+window.screenTop;
WinPop=window.open("info.html","","fullscreen");
WinPop.resizeTo(scrWidth,scrHeight);
WinPop.moveTo(placementx,placementy);
WinPop.document.focus();
}
}

johnalbu
07-18-2002, 02:59 AM
<html>
<head>
<title>Auto Centering new POP up Window</title>
<!--
This file retrieved from the JS-Examples archives
http://www.js-examples.com
100s of free ready to use scripts, tutorials, forums.
Author: Eric King - http://redrival.com/eak/index.shtml
-->

<script type=text/javascript>
var win= null;
function NewWindow(mypage,myname,w,h,scroll){
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars='+scroll+',';
settings +='resizable=yes';
win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
</script>


</head>
<body>

<a href="newpagename for window goes here.htm" onclick="NewWindow(this.href,'name','200','200','no');return false">
click to open new window</a>


</body>
</html>

johnalbu
07-18-2002, 06:34 AM
<html>
<head>
<title>Open New Window and Position by % of Screen Size</title>
<SCRIPT LANGUAGE = "javascript">

// variable definitions
// sw = screen width
// sh = screen height

// NOTE: These Var's use percentages so they will work at all screen resolutions
// ww = window width
// wh = window height
// wt = window top
// wl = window left

var win= null;
function NewWindow(mypage,myname,scroll){

var sw = screen.width
var sh = screen.height

// Enter as a decimal percent of screen size
var ww = .25
var wh = .35
var wt = .25
var wl = .50

// Calculations to convert percentages to pixels for any screen resolution
ww = Math.ceil(sw * ww) // you could enter actual pixels replacing Math.ceil(sw * ww)
wh = Math.ceil(sh * wh) // "
wt = Math.ceil(sh * wt) // "
wl = Math.ceil(sw * wl) // "

var settings ='height='+wh+',';
settings +='width='+ww+',';
settings +='top='+wt+',';
settings +='left='+wl+',';
settings +='scrollbars='+scroll+',';
settings +='resizable=yes';

win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
</script>


</head>
<body>

<a href="Enter new window web page here.htm"
onclick="NewWindow(this.href,'name','no');return false">
click to open new window</a>




</body>
</html>

Walt
07-18-2002, 02:43 PM
Thank you so much!

This script is exactly what I need.

Walter