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!

Open Pop-up in Center of Window

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
Posting this for anyone looking for a quick reference to opening a pop-up window so that it is centralized based on the available screen width:
Code:
<script language="JavaScript" type="text/javascript">
function openWinSite(){
 var strPg; 
 var w = window.screen.availWidth*.25;
 var h = window.screen.availheight*.25;
 var strParams = 'left='+ w +',top='+ h +',height=360,width=620,toolbar=no,menubar=no,...,scrollbars=no';
 strPg = "yourPage.htm"
 myWindow = window.open(strPg, 'newWin', strParams)
}
</script>
Simple enough but did not find this argument in a quick search - primarily submitting w.r.t. title of thread.
 
Sorry, this should have been a helpful tip; not a Question.
 
this all depends on your definition of "center". based on your code above, screens of varying sizes will handle this code differently. and that's only if you fix the part that will error out: it should be availHeight, not availheight.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks clFlaVa. Case is strictly adhered to in Javascript, I'm learning that.

Yes the above works only for a perfect square. For irregular rectangles you would need:
Code:
<script language="JavaScript" type="text/javascript">
function openWinSite(){
 var strPg; 
 var w = window.screen.availWidth;
 w = (w-620)/2;
 var h = window.screen.availHeight;
 h = (h-360)/2;
 var strParams = 'left='+ w +',top='+ h +',height=360,width=620,toolbar=no,location=no,menubar=no,...,scrollbars=no';
 strPg = "CertRules.htm"
 myWindow = window.open(strPg, 'newWin', strParams)
}
</script>
..to adjust for the irregular height and width in the pop-up dimensions.
 
For anyone wanting to do this, but taking screen resolution into account, there's an FAQ that's been here since May 2003:

faq216-3542

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks BillyRay, should have discovered this but did not come up in my Search - next time for sure will look into the FAQ;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top