javascript code to centre browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Crook

    javascript code to centre browser

    I placed the following code in my html file

    window.resizeTo (1000,700)
    window.moveTo(( screen.availWid th/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 Thompson

    #2
    Re: javascript code to centre browser

    On Tue, 6 Jul 2004 20:27:16 +0100, Andrew Crook wrote:
    [color=blue]
    > I wish the browser to resize and centre on screen when the user goes to my
    > site.[/color]

    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

    Comment

    • Ivan Marsh

      #3
      Re: javascript code to centre browser

      On Tue, 06 Jul 2004 20:27:16 +0100, Andrew Crook wrote:
      [color=blue]
      > I wish the browser to resize and centre on screen when the user goes to my
      > site.[/color]

      I don't.

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

      Comment

      • kaeli

        #4
        Re: javascript code to centre browser

        In article <cceue5$59u$1$8 30fa17d@news.de mon.co.uk>,
        andrew@NOSPAM_a ndicrook.demon. co.uk enlightened us with...[color=blue]
        > I placed the following code in my html file
        >
        > window.resizeTo (1000,700)
        > window.moveTo(( screen.availWid th/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?
        >[/color]

        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.availWid th and screen.availHei ght are cross
        browser, but I seem to recall that they are not.

        Anyway, try
        window.moveTo(( screen.availWid th/2)-(1000/2),(screen.avai lHeight/2)-
        (700/2));

        --
        --
        ~kaeli~
        Once you've seen one shopping center, you've seen a mall.



        Comment

        • David Dorward

          #5
          Re: javascript code to centre browser

          Andrew Crook wrote:
          [color=blue]
          > I placed the following code in my html file
          >
          > window.resizeTo (1000,700)[/color]

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

          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.
          [color=blue]
          > The resize seems to work fine, however, the move does not seem to work.
          > Tested under IE6 and firefox.[/color]

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

          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.


          [color=blue]
          > any ideas how to make this work?[/color]

          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

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: javascript code to centre browser

            "Andrew Crook" <andrew@NOSPAM_ andicrook.demon .co.uk> writes:
            [color=blue]
            > I placed the following code in my html file
            >
            > window.resizeTo (1000,700)
            > window.moveTo(( screen.availWid th/2)-(1000/2),(availHeight/2)-(700/2));[/color]

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

            Missing "screen." before "availHeigh t". I recommend using:

            window.moveTo(( screen.availWid th-1000)>>1,(scree n.availHeight-700)>>1);

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

            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 :)
            [color=blue]
            > any ideas how to make this work?[/color]

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

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Andrew Crook

              #7
              Re: javascript code to centre browser

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

              AndiC


              "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
              news:ekno7uha.f sf@hotpop.com.. .[color=blue]
              > "Andrew Crook" <andrew@NOSPAM_ andicrook.demon .co.uk> writes:
              >[color=green]
              > > I placed the following code in my html file
              > >
              > > window.resizeTo (1000,700)
              > > window.moveTo(( screen.availWid th/2)-(1000/2),(availHeight/2)-(700/2));[/color]
              >
              > I assume this page is for personal use only.
              > Resizing other people's windows (potentially beyond their screen size)
              > is not considered polite.
              >[color=green]
              > > The resize seems to work fine, however, the move does not seem to work.[/color]
              >
              > Missing "screen." before "availHeigh t". I recommend using:
              >
              > window.moveTo(( screen.availWid th-1000)>>1,(scree n.availHeight-700)>>1);
              >
              > The reason for using >>1 instead of /2 is that the former also converts
              > to an integer.
              >[color=green]
              > > Tested under IE6 and firefox.
              > > I wish the browser to resize and centre on screen when the user goes to[/color][/color]
              my[color=blue][color=green]
              > > site.[/color]
              >
              > 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 :)
              >[color=green]
              > > any ideas how to make this work?[/color]
              >
              > Try adding "screen.". Then reconsider whether you *really* want to do[/color]
              this.[color=blue]
              >
              > /L
              > --
              > Lasse Reichstein Nielsen - lrn@hotpop.com
              > DHTML Death Colors:[/color]
              <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue]
              > 'Faith without judgement merely degrades the spirit divine.'[/color]


              Comment

              • Andrew Crook

                #8
                Re: javascript code to centre browser

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

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

                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.
                [color=blue]
                > Eugh. My (for example) "screen" is split across two monitors. That would[/color]
                put[color=blue]
                > 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.[/color]

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

                many thanks

                AndiC

                "David Dorward" <dorward@yahoo. com> wrote in message
                news:ccf1bp$fij $1$830fa7a5@new s.demon.co.uk.. .[color=blue]
                > Andrew Crook wrote:
                >[color=green]
                > > I placed the following code in my html file
                > >
                > > window.resizeTo (1000,700)[/color]
                >
                > Last time I looked at any such statistics, they suggested that size[/color]
                wouldn't[color=blue]
                > fit on the screens of about 45% of users.
                >[color=green]
                > > window.moveTo(( screen.availWid th/2)-(1000/2),(availHeight/2)-(700/2));[/color]
                >
                > Eugh. My (for example) "screen" is split across two monitors. That would[/color]
                put[color=blue]
                > 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.
                >[color=green]
                > > The resize seems to work fine, however, the move does not seem to work.
                > > Tested under IE6 and firefox.[/color]
                >
                > Firefox has a "Don't let JavaScript move or resize windows" option. There[/color]
                is[color=blue]
                > a good reason for this.
                >[color=green]
                > > I wish the browser to resize and centre on screen when the user goes to[/color][/color]
                my[color=blue][color=green]
                > > site.[/color]
                >
                > 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[/color]
                whatever[color=blue]
                > window size the user cares to present you with), rather then risking
                > disaster.
                >
                > http://www.allmyfaqs.com/faq.pl?AnySizeDesign
                >[color=green]
                > > any ideas how to make this work?[/color]
                >
                > Oddly enough, I don't seem to have any inclination to get that code[/color]
                working.[color=blue]
                > 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[/color]


                Comment

                • Richard Cornford

                  #9
                  Re: javascript code to centre browser

                  Andrew Crook wrote:[color=blue]
                  > David Dorward wrote:[/color]
                  <snip>[color=blue][color=green]
                  >> 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.[/color]
                  >
                  > statistically how many people will that effect :-).. but see you point[/color]
                  <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.


                  Comment

                  Working...