How to center a popup window on screen using JavaScript?

JavascriptWeb DevelopmentFront End Technology

To center a popup window on the screen, you can try to run the following code

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         function myPopup(myURL, title, myWidth, myHeight) {
            var left = (screen.width - myWidth) / 2;
            var top = (screen.height - myHeight) / 4;
            var myWindow = window.open(myURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + myWidth + ', height=' + myHeight + ', top=' + top + ', left=' + left);
         }
      </script>
      <button onclick=" myPopup ('http://www.qries.com', 'web', 1050, 550);">Open Qries.com</button>
   </body>
</html>
raja
Published on 30-Jan-2018 16:24:10
Advertisements