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:
I looked on the Internet and saw examples like mine, could someone tell me what’s wrong?
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..
– Matheus Luz
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 atop
to center the window.– Daniel Ribeiro
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 )
– Bacco
Simple problems, simple solutions @Bacco... I just wanted to see all arguments that the
open()
receives xD– Daniel Ribeiro
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
– Matheus Luz
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.
– Bacco
Okay, thanks guys! If I knew how, I’d give +1 to you
– Matheus Luz
@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
– Bacco
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...
– Daniel Ribeiro
@Matheusluz Please, if the answer really solved your problem, mark it as correct for the question to be given as solved.
– Daniel Ribeiro