• support@answerspoint.in

How to open new window (popup) and center on screen

Advertisement

Method 1: Center a popup window on screen

Here is a java script function that opens a new window (popup) and puts it on center of screen:

 

The link sample:

CLICK TO OPEN POPUP

This is a COPY and PASTE script, tested on Chrome, Internet Explorer and Firefox.

Method 2: Center a popup window on screen (Single / Dual Monitor solution).

 

The link sample:

CLICK TO OPEN POPUP

 

<button onclick="openPopup()">Open popup</button>

<script>
function openPopup() {
  const width = 600;
  const height = 400;

  const left = (screen.width - width) / 2;
  const top = (screen.height - height) / 2;

  window.open(
    'https://example.com',
    'popupWindow',
    `width=${width},height=${height},top=${top},left=${left},resizable=yes,scrollbars=yes`
  );
}
</script>

 

 

    Facebook Share        
       
  • publish 8 years ago
  • viewed 52 times
  • active 2 months ago

Top Rated Blogs