Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > javascript code to centre browser

Reply
Thread Tools

javascript code to centre browser

 
 
Andrew Crook
Guest
Posts: n/a
 
      07-06-2004
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


 
Reply With Quote
 
 
 
 
Ivan Marsh
Guest
Posts: n/a
 
      07-06-2004
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.

 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      07-06-2004
In article <cceue5$59u$1$(E-Mail Removed)>,
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

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      07-06-2004
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
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      07-06-2004
"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 - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Andrew Crook
Guest
Posts: n/a
 
      07-07-2004
okay hands up!! I surrender... the code has been removed

AndiC


"Lasse Reichstein Nielsen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "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 - (E-Mail Removed)
> DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
> 'Faith without judgement merely degrades the spirit divine.'



 
Reply With Quote
 
Andrew Crook
Guest
Posts: n/a
 
      07-07-2004
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" <(E-Mail Removed)> wrote in message
news:ccf1bp$fij$1$(E-Mail Removed)...
> 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



 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      07-07-2004
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a web page in the centre in a browser. Bundy HTML 17 12-24-2006 09:19 AM
Cannot centre page in firefox browser ( it works in Internet Explorer) Bundy HTML 4 11-20-2006 02:22 AM
Firefox Centre Firefox Centre Firefox 0 12-15-2005 11:04 AM
Sort of OT but not - Pinnacle show centre Rachael the Wiccan Rat Wireless Networking 0 09-17-2004 01:15 PM
Re: exam centre in london Justin Dutoit MCSD 0 08-15-2003 02:52 AM



Advertisments