How to center these

Hi, I can ask some help is it possible to center the window.open()?..i want to open a new window and it will center to the parent browser when it opens.

Thank you in advance.

Hi jemz,

As per the documentation, you can pass window.open the coordinates of where on the screen it should open.

Therefore, all you need to do is use JS to get the width and height of the current viewport and calculate the position dynamically, based on the width and height of your new window.

Something like this:

function popupwindow(url, title, w, h) {
  var left = (screen.width/2)-(w/2);
  var top = (screen.height/2)-(h/2);
  return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

I found this here: http://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen
If you need a hand implementing this, let me know.

Hi pullo,

It’s working now these solved my problem :slight_smile:

Thank you.