By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,393 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,393 IT Pros & Developers. It's quick & easy.

javascript code to centre browser

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Tue, 6 Jul 2004 20:27:16 +0100, Andrew Crook wrote:
I wish the browser to resize and centre on screen when the user goes to my
site.


What is it that makes you think your users
are incapable of resizing and centering
*their* browser when *they* want? :-O

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2

P: n/a
On Tue, 06 Jul 2004 20:27:16 +0100, Andrew Crook wrote:
I wish the browser to resize and centre on screen when the user goes to my
site.


I don't.

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #3

P: n/a
In article <cc*******************@news.demon.co.uk>,
andrew@NOSPAM_andicrook.demon.co.uk enlightened us with...
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));

--
--
~kaeli~
Once you've seen one shopping center, you've seen a mall.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

P: n/a
Andrew Crook wrote:
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.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #5

P: n/a
"Andrew Crook" <andrew@NOSPAM_andicrook.demon.co.uk> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6

P: n/a
okay hands up!! I surrender... the code has been removed

AndiC
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:ek**********@hotpop.com...
"Andrew Crook" <andrew@NOSPAM_andicrook.demon.co.uk> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 23 '05 #7

P: n/a
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

"David Dorward" <do*****@yahoo.com> wrote in message
news:cc*******************@news.demon.co.uk... Andrew Crook wrote:
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.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is

Jul 23 '05 #8

P: n/a
Andrew Crook wrote:
David Dorward wrote:

<snip>
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

<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.
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.