Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1399 How can I open a popup window in the middle of the screen?

You are here: irt.org | FAQ | JavaScript | Window | Q1399 [ previous next ]

Try the following which works in JavaScript 1.2:

<script language="JavaScript"><!--
function openWindow(width,height) {
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

    window.open('nextpage.htm','newWin','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}
//--></script>

<form>
<input type="button" onClick="openWindow(100,200)" value="Click Me">
</form>

Feedback on 'Q1399 How can I open a popup window in the middle of the screen?'

©2018 Martin Webb