Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created July 29, 2011 12:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Amitesh/1113683 to your computer and use it in GitHub Desktop.
Save Amitesh/1113683 to your computer and use it in GitHub Desktop.
Open popup window in center of screen in javascript
var top = window.screen.height - 300;
top = top > 0 ? top/2 : 0;
var left = window.screen.width - 400;
left = left > 0 ? left/2 : 0;
var uploadWin = window.open(url,"Upload Chapter content","width=400,height=300" + ",top=" + top + ",left=" + left);
uploadWin.moveTo(left, top);
uploadWin.focus();
@div-coder
Copy link

This can be used also to center popup window in center of screen in javascript
var width = 600;
var height = 600;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var popup = window.open(pdfUrl, "_blank", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment