Problem with javascript open

Asked

Viewed 60 times

4

I’m using the following code snippet:

window.open('provas-final.php','height=320, width=320', 'gl');

to open the file "proofs-final.php" and in the command itself I am saying the width and height of the window that will open (320px), but when it runs, it opens a window totally contrary to the dimensions that I am passing, as the image:

inserir a descrição da imagem aqui

I looked on the Internet and saw examples like mine, could someone tell me what’s wrong?

1 answer

8

An argument is missing from your function call. The function waits window.open(URL,name,specs,replace) and you’re passing only 3 arguments, so your second argument 'height=320, width=320' is being considered as name. Do it this way:

window.open("home.php","_blank","height=320, width=320",false);

w3schools - If you need more information about the function open() see this link.

  • Oops, it worked, thanks! Another question, can you make the window open in the center of the page? it is opening in the upper left corner..

  • 1

    Take a look at the link I put at the end of the answer, there are all specs you can use... In this case, set a left and a top to center the window.

  • 2

    Earned my +1 for being the correct answer (despite using just the w3schools as reference with so much good source of information on the internet :P )

  • Simple problems, simple solutions @Bacco... I just wanted to see all arguments that the open() receives xD

  • I’ve seen it, the problem is I’d like to set a center for any monitor, if I set a left and a top will look disproportionate according to the monitor used

  • 1

    There will be the case of using a window.moveTo(); with the ( screen coordinates - those of the window ) / 2 approximately, but it is a very different matter.

  • Okay, thanks guys! If I knew how, I’d give +1 to you

  • 4

    @Matheus If Daniel’s answer solved, you can click the little green "v" on her side. You can vote on the answers as well, and a number of other things as you earn more reputation points on the site. Suggested reading: Community FAQ

  • If you want me to add it to the answer later, but I did a sketch so you can center the window for now... var widthWindow = 320; var heightWindow = 320; var leftWindow = ((screen.width/2) - (widthWindow/2)); var topWindow = ((screen.height/2) - (heightWindow/2)); var specs = "width="+widthWindow+",height="+heightWindow+",top="+topWindow+",left="+leftWindow; window.open("home.php","_Blank",specs,false); ... I think this does not work if the person has a setup with two monitors, but at the moment I have only one and I could not test...

  • @Matheusluz Please, if the answer really solved your problem, mark it as correct for the question to be given as solved.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.