Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery open new window centered with fixed size [duplicate]

Possible Duplicate:
Center a popup window on screen?

I have 4 different links, all of which need to open a new window which will target 4 different html files.

When the links are clicked, it needs to open the html file in question in a new window, both:

  • Centered
  • Fixed size 900 x 600

I have found this below, but it doesnt seem to cater for centering of the window

http://jquerybyexample.blogspot.com/2012/05/open-link-in-new-tab-or-new-popup.html

Cheers

like image 955
John Avatar asked Nov 07 '12 14:11

John


1 Answers

To center the new window, give it a left and top value half of the screen size - half of the window size :

var left  = ($(window).width()/2)-(900/2),
    top   = ($(window).height()/2)-(600/2),
    popup = window.open ("", "popup", "width=900, height=600, top="+top+", left="+left);

FIDDLE

like image 125
adeneo Avatar answered Oct 13 '22 17:10

adeneo