Self resize and center a window using javascript (no jquery) on page load

a 夏天 提交于 2019-11-30 14:50:40

I personally would advice against Popups an Javascript window manipulation. (due to Popup Blockers, Javascript errors, ...) A Overlay would probably be better.

Here would be an other Solution.

File one(Link should point to this Helper, that opens the Video HTML)

<html>
<body>
<script>
    var windowWidth = 400;
    var windowHeight = 200;
    var xPos = (screen.width/2) - (windowWidth/2);
    var yPos = (screen.height/2) - (windowHeight/2);
    window.open("popup.html","POPUP","width=" 
    + windowWidth+",height="+windowHeight +",left="+xPos+",top="+yPos);
</script>
</body>
</html>

File Two (Video that closes Helper)

<html>
<body onload="window.opener.close();">
</body>
</html>

Got it working with:

<script language="javascript">

  function resizeVideoPage(){
    var width = 600;
    var height = 400;
    window.resizeTo(width, height);
    window.moveTo(((screen.width - width) / 2), ((screen.height - height) / 2));      
  }
</script>

// Then...

<body onload="resizeVideoPage();"></body>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!