Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Positioning a window

Status
Not open for further replies.

emozley

Technical User
Joined
Jan 14, 2003
Messages
769
Location
GB
Hi,

I have a calendar that you can click on and that causes a popup to open that lets you enter holiday information.

The popup is created with the following:

<SCRIPT>
function entercategory(theUrl) {
window.open(theUrl, 'jav', 'width=640,height=320,resizable=no,scrollbars=auto');
}
</SCRIPT>

Sometimes when it opens part of it is sticking off the screen and it is annoying having to drag it back to a point where you can see everything. Is there any way of making the popup appear in the middle of the screen?

Thanks very much

Ed
 
use the screenX and screenY properties in the third parameter of your window.open call. set them to 0 for the top left. if the exact middle of the screen is important to you, you will need to do a little more work determining the size of the user's screen and then, from there, determining the middle: just do a google for "javascript center popup screen".



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
emozley, check this link for some code/tips on detecting the screen height and width on the client's PC so you can calculate the position of your popup.

Implementation varies between browsers but you should be able to get something reasonable working. Just remember that you will have to take into account the size of your popup and subtract accordingly to get the centering correct.

At my age I still learn something new every day, but I forget two others.
 
Hi,

Thanks for this - I think I'm just about there just having a few problems with the syntax:

<SCRIPT>
function entercategory(theUrl) {
window.open(theUrl, 'jav', 'width=640,height=320,top=((screen.height-320)/2),left=((screen.width-640)/2),resizable=no,scrollbars=auto');
}
</SCRIPT>

It's not detecting any errors but it's assuming the figures are 0 and putting it at the top left hand corner.
 
The properties you are setting are all within quotes and being treated as a string so the screen.height command is never treated as a command.

Try building the options string in a variable like the url is.
Code:
function entercategory(theUrl) {
var theOptions = 'width=640,height=320,top=' + ((screen.height-320)/2) + ',left=((screen.width-640)/2),resizable=no,scrollbars=auto';
   window.open(theUrl, 'jav', theOptions);
}

At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top