Search code examples
javascripthtmlwindowsize

how to size a window created in HTML with window.open to full width of the monitor and limit the height


I have a code to open a new window with a specific width and height. If I put numeric values it works, but i want to size it to full width and certain height (height will be equal to width x certain ratio). The problem I have is that I don't know how to make the window full width, I don't know why window.width or window.innerwidth doesn't work. How I can do it?

<html>
<head>
</head>
<body>
<input type="button" onclick='var myW=window.open

("http://www.google.com/","mywindow","width = window.innerWidth , height = 300");'>
</body>
</html>

Solution

  • You can access your monitor size with window.screen.width, anyway you have to concatenate the window property with the string in a proper way

    window.open("http://www.google.com/","mywindow","width = " + window.screen.width + ", height = 300")