Search code examples
javascripthtmlwindow.open

Window.open problems in html


I am trying to open a new window with a button. The window needs to have a specific height and width. Whenever I click the "open" button it just opens a completely new tab.

var aWindow;

function openWindow() {
  aWindow = window.open("", "", "width=400, height = 200");
}

function closeWindow() {
  if (aWindow) {
    aWindow.close();
  }
}
<html>

<body>
  <button onclick="openWindow();">Open</button>
  <button onclick="closeWindow();">Close</button>
</body>

</html>


Solution

  • Try to use this code

     window.open('https://www.google.co.in/','_blank','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes,resizable=yes, width=10px, height=20px')
    

    DEMO LINK