Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Window | Q1804 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.