-1

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>
Nik
  • 1,589
  • 2
  • 15
  • 23

3 Answers3

1
window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=300px,height=300px');

Try this code tested

gowtham rajan
  • 322
  • 2
  • 14
0

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

JIJOMON K.A
  • 1,290
  • 3
  • 12
  • 29
0
<input type="button" value="Open a Popup Window" onclick="popupFunction('https://stackoverflow.com')">

<script>
    // Popup window function
    function popupFunction(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>
Srikrushna
  • 4,366
  • 2
  • 39
  • 46