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

center a popup

Status
Not open for further replies.

diarratech

Technical User
Joined
Jul 7, 2000
Messages
41
Location
FR
I have trouble centering my popup on a page. Can anyone help me. I know i need to use the following variable to center the popup
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
but it doesn't work

Here is my function popup.js
var newWin = null;
function closeWin(){
if (newWin != null){
if(!newWin.closed)
newWin.close();
}
}
function popUp(strURL,strType,strHeight,strWidth) {
closeWin();
var strOptions="";
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,
height="+strHeight+",width="+strWidth;
newWin = window.open(strURL, 'newWin', strOptions);
newWin.focus();
}

I call it this way <a href="ma_fenetre.htm"
onclick="popUp(this.href,'console',400,200);return false;">link</a>

thanks
 
>if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,
height="+strHeight+",width="+strWidth;


[1] toolbar etc parameters have to be assigned a value (yes|1) or (no|0) to be effective.
[2] To center, at least you have to assign the top and left edges distances.

Suppose listing toolbar etc you mean to keep them (yes or 1), otherwise, they should be set to =no or =0.
[tt]
if (strType=="elastic") strOptions="toolbar=1,menubar=1,scrollbars=1,resizable=1,location=1,height=" + strHeight + ",width=" + strWidth + ",top=" + wint + ",left=" + winl;
[/tt]
[3] The functionality does not warrant pixel-perfect rendrement, but you might fine .availHeight and .availWidth more satisfactory.
[tt]
var winl = (screen.availWidth-strWidth)/2; //or screen.width
var wint = (screen.availHeight-strHeight)/2; //or screen.height
[/tt]
[3.1] In any case, put them inside the function popUp().
[4] Your link assigns "console" to the function. If you want to test the effect, why not assign "elastic" to it?
[4.1] You might mean the reverse of the parameter (400, 200), ie, (...,200,400) meaning height 200 width 400. Just guessing.
 
OK! I will try this tonite. Thanks
 
It is working great! Thank you very much!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top