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

Q1804 How do I always popup a window in the center of the parent window regardless of where the parent window is?

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

Try:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="JavaScript"><!--
function popup(url) {
  var w = 480, h = 340;
  if (document.all) {
    /* the following is only available after onLoad */
    w = document.body.clientWidth;
    h = document.body.clientHeight;
    x = window.screenTop;
    y = window.screenLeft;
  }
  else if (document.layers) {
    w = window.innerWidth;
    h = window.innerHeight;
    x = window.screenX;
    y = window.screenY;
  }
  var popW = 300, popH = 200;
  var leftPos = ((w-popW)/2)+y, topPos = ((h-popH)/2)+x;
  window.open(url,'popup','width='+popW+',height='+popH+',top='+topPos+',left='+leftPos);
}
//--></script>

</head>

<body onLoad="popup('page.html')">

</body>
</html>

©2018 Martin Webb