javascript code to centre browser

A

Andrew Crook

I placed the following code in my html file

window.resizeTo(1000,700)
window.moveTo((screen.availWidth/2)-(1000/2),(availHeight/2)-(700/2));

The resize seems to work fine, however, the move does not seem to work.
Tested under IE6 and firefox.
I wish the browser to resize and centre on screen when the user goes to my
site.

any ideas how to make this work?

regards

AndiC
 
K

kaeli

I placed the following code in my html file

window.resizeTo(1000,700)
window.moveTo((screen.availWidth/2)-(1000/2),(availHeight/2)-(700/2));

The resize seems to work fine, however, the move does not seem to work.
Tested under IE6 and firefox.
I wish the browser to resize and centre on screen when the user goes to my
site.

any ideas how to make this work?

You don't if the user has moveTo turned off, which some of us do.
Actually, I have resizeTo turned off, too. I don't like my windows
mucked with.
It's very bad to do to people who use tabbed browsers, like Netscape 7,
Mozilla, and Opera. You screw up my whole browser that has more windows
than just yours in it. I turned off that nonsense because of people
doing what you are doing.

Also, this would not work very well for people with resolutions outside
the values you hard-coded. Bad idea. Most people use 800 by 600
resolution. You can't center a 1000 by 700 window in there.

That all said...you forgot to preface availHeight with screen. And I
don't know if screen.availWidth and screen.availHeight are cross
browser, but I seem to recall that they are not.

Anyway, try
window.moveTo((screen.availWidth/2)-(1000/2),(screen.availHeight/2)-
(700/2));

--
 
D

David Dorward

Andrew said:
I placed the following code in my html file

window.resizeTo(1000,700)

Last time I looked at any such statistics, they suggested that size wouldn't
fit on the screens of about 45% of users.
window.moveTo((screen.availWidth/2)-(1000/2),(availHeight/2)-(700/2));

Eugh. My (for example) "screen" is split across two monitors. That would put
a 5" gap in the middle of the window.... and one monitor is rather higher
then the other, so the two halves wouldn't line up.
The resize seems to work fine, however, the move does not seem to work.
Tested under IE6 and firefox.

Firefox has a "Don't let JavaScript move or resize windows" option. There is
a good reason for this.
I wish the browser to resize and centre on screen when the user goes to my
site.

Things you can control: The way your document flows in the user's window.

Things you can not control reliably: The size of the user's window.

Things you can not control at all: The size and layout of the user's
desktop.

Focus on what you can control (making a site that will flow to fit whatever
window size the user cares to present you with), rather then risking
disaster.

http://www.allmyfaqs.com/faq.pl?AnySizeDesign
any ideas how to make this work?

Oddly enough, I don't seem to have any inclination to get that code working.
It does strike me as rather wasteful to have the browser workout what
1000/2 and what 750/2 are every time the page is loaded though.
 
L

Lasse Reichstein Nielsen

Andrew Crook said:
I placed the following code in my html file

window.resizeTo(1000,700)
window.moveTo((screen.availWidth/2)-(1000/2),(availHeight/2)-(700/2));

I assume this page is for personal use only.
Resizing other people's windows (potentially beyond their screen size)
is not considered polite.
The resize seems to work fine, however, the move does not seem to work.

Missing "screen." before "availHeight". I recommend using:

window.moveTo((screen.availWidth-1000)>>1,(screen.availHeight-700)>>1);

The reason for using >>1 instead of /2 is that the former also converts
to an integer.
Tested under IE6 and firefox.
I wish the browser to resize and centre on screen when the user goes to my
site.

I don't. It won't work in browsers using tabs or MDI. It works badly for
people with more than one monitor. It is intrusive and annoying.
Good thing it won't work in my browser then (Opera in MDI mode :)
any ideas how to make this work?

Try adding "screen.". Then reconsider whether you *really* want to do this.

/L
 
A

Andrew Crook

the code has been removed
Last time I looked at any such statistics, they suggested that size wouldn't
fit on the screens of about 45% of users.

I am thinking of redesigning the page at 800x600 static
Focus on what you can control (making a site that will flow to fit whatever
window size the user cares to present you with), rather then risking
disaster.

yeah format everything in tables using percentages that way it should
resize well, only what would be the best way to deal with images, I would
also need to keep aspect ratio.
Eugh. My (for example) "screen" is split across two monitors. That would put
a 5" gap in the middle of the window.... and one monitor is rather higher
then the other, so the two halves wouldn't line up.

statistically how many people will that effect :).. but see you point

many thanks

AndiC
 
R

Richard Cornford

Andrew said:
David Dorward wrote:

statistically how many people will that effect :).. but see you point
<snip>

Statistically the number will be tiny, but you might like to think a bit
about who these people are. They have the money to purchase multiple
monitors (or maybe just had a spare kicking around), and the inclination
and skills to configure their computers to use them. They are probably
almost entirely well-paid IT professionals; exactly the people any
e-commerce endeavour wants using its services (because they have money
to spend and are not afraid of spending it over the Internet).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top