javascript code to centre browser

Discussion in 'Javascript' started by Andrew Crook, Jul 6, 2004.

  1. Andrew Crook

    Andrew Crook Guest

    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
    Andrew Crook, Jul 6, 2004
    #1
    1. Advertising

  2. Andrew Crook

    Ivan Marsh Guest

    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.
    Ivan Marsh, Jul 6, 2004
    #2
    1. Advertising

  3. Andrew Crook

    kaeli Guest

    In article <cceue5$59u$1$>,
    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
    kaeli, Jul 6, 2004
    #3
  4. 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
    David Dorward, Jul 6, 2004
    #4
  5. "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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jul 6, 2004
    #5
  6. Andrew Crook

    Andrew Crook Guest

    okay hands up!! I surrender... the code has been removed

    AndiC


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

    <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    > 'Faith without judgement merely degrades the spirit divine.'
    Andrew Crook, Jul 7, 2004
    #6
  7. Andrew Crook

    Andrew Crook Guest

    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" <> wrote in message
    news:ccf1bp$fij$1$...
    > 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
    Andrew Crook, Jul 7, 2004
    #7
  8. 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.
    Richard Cornford, Jul 7, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kayodeok

    Dead Centre

    kayodeok, Jan 3, 2004, in forum: HTML
    Replies:
    11
    Views:
    768
    PeterMcC
    Jan 4, 2004
  2. Andy:P
    Replies:
    8
    Views:
    511
    Andy Peat
    Jan 15, 2004
  3. Tim Stokes

    Centre align content on the page

    Tim Stokes, Jun 17, 2004, in forum: HTML
    Replies:
    2
    Views:
    395
    Tim Stokes
    Jun 17, 2004
  4. Bundy
    Replies:
    4
    Views:
    484
    dorayme
    Nov 20, 2006
  5. Bundy
    Replies:
    17
    Views:
    574
    Blinky the Shark
    Dec 24, 2006
Loading...

Share This Page