Skip to content

JavaScript open popup window

  • by

Use JavaScript’s window.open() method to open the popup window in JavaScript. Popup windows are different from simply opening a new browser window.

open()
open(url)
open(url, target)
open(url, target, windowFeatures)

JavaScript open popup window

Simple example code calls the function, passing the URL as a parameter, whenever you want to open a popup window.

<!DOCTYPE html>
<html>
<body>
  <input type="button" value="Open Popup" onclick="basicPopup('https://tutorial.eyehunts.com/')">

  <script>
    function basicPopup(url) {
      popupWindow = window.open(url,'popUpWindow','height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
    }
  </script>

</body>
</html>

Output:

JavaScript open popup window

Javascript to open link in a new pop-up window

<a href="//somesite.com/"  class="social_share_link"
onclick="return !window.open(this.href, 'somesite', 'width=500,height=500')"
target="_blank">Share</a>

Do comment if you have any doubts or suggestions on this JS topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *