Click to See Complete Forum and Search --> : window position problem


munna
08-22-2003, 05:28 AM
Hi,
I'm trying to open a new window in the middle of the viewer's screen, and have got this -- but it doesn't work. Please someone tell me what I'm doing wrong here?

<a href ="#" onClick="window.open('netsearch.html', 'netsearch', 'resizable, toolbar=no, location=no, status=no, scrollbars=no, menubar=no, titlebar=no, height=315, width=215',top='((screen.availHeight/2)-(315/2))',left='((screen.availWidth/2)-(215/2))')">
<img src="images/globe.gif" width="25" height="25" border ="0" align="middle" /></a></td>

AdamGundry
08-22-2003, 05:58 AM
Try this:
<script type="text/javascript">
function centeredPopup(url, title, width, height){
window.open(url, title, 'width=' + width + ',height=' + height + ',top=' + parseInt((screen.availHeight/2)-(height/2)) + ',left=' + parseInt((screen.availWidth/2)-(width/2)));
return false;
}
</script>

<a href="netsearch.html" onclick="return centeredPopup(this.href, 'netsearch', 215, 315)"><img src="images/globe.gif" width="25" height="25" border ="0" align="middle" /></a>
Adam

Charles
08-22-2003, 06:12 AM
You would do well to use Math.round() inplace of parseInt() above. Both ways screen.availHeight returns a string primitive which has to be turned into a String object so that it can be turned into a number primitive and divided by two which is a number primitive. Math.round() takes a number but parseInt() takes a string so our number primitive will have to be turned into a string and then back into number again.

AdamGundry
08-22-2003, 10:13 AM
Well spotted, Charles. I stand corrected.

Adam