0
function myFunction(){
window.open("http://example.com", "myWindow", "height=150, 
width=150");
}

Do I really need to add "myWindow" just to load the new window in a size of 150X150? Whenever I remove the "myWindow" code, the sample site is loaded in full-screen. And yes I've tried adding "" and it worked. Why is it even necessary? I've also tried the code above but doesn't work as well:

function myFunction(){
window.open("http://example.com");
window.resizeTo(150, 150)
}
2
  • 1
    Have you tried replacing "myWindow" with ""? Commented Apr 8, 2018 at 9:35
  • @D.Pardal I've tried and yes it worked. But my question was, why was it necessary to include it? Commented Apr 8, 2018 at 9:36

4 Answers 4

1

According to the API specifications of Window.open(), you specify the window features in the 3rd parameter. Therefore, you need to set the 2nd parameter, otherwise whatever you specify in the 2nd parameter will be interpreted as the window name.

Sign up to request clarification or add additional context in comments.

1 Comment

I get it now...so the height and width will be applied to the 2nd parameter...thank you
0

you can pass _blank instead of myWindow.

Comments

0

window.open is rather browser specific, you need to test it. There are ethical problems surrounding its use so some attributes do not operate in newer browsers because of malicious javascript programming.

re: popup blockers (ethics of functioning these attributes) !

(may cause user problems) resizable= , fullscreen= , replace=

<!-- no DTD no lang no full script tag declaration -->
 <html>

 <head>
   <title> test </title>
 </head>

  <body>
 <script>
window.open("https://stackoverflow.com/questions/49716443/opening-a-window-using-windows-open-in-javascript", "_new", "height=150, width=800, fullscreen=no, location=no, menubar=no, status=no, titlebar=no, toolbar=no");
 </script>

  </body>

</html>

"myName" as a parameter value is like an id for the early javascript to have a clear reference to the window for programming.

Here's a good link for modern x-browser. https://developer.mozilla.org/en-US/docs/Web/API/Window/open

Comments

0

if you don't want to set a custom name, according to the docs you can set the name string as "_blank" which is the default. This parameter is necessary because all window.open parameters are positional, that means that if you want to set specs you need to define URL and name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.