Close a window if it is already open

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roger Withnell

    Close a window if it is already open

    I open a new window from the current window to display maps.

    Several maps of different sizes can be displayed. The function is given the
    size of the map and adjusts the window size accordingly.

    If a new window is already open, the new map sizes are ignored and the new
    map is is either too small for the existing "new" window or too big, which
    is a more serious problem!

    I've tried to fix this by closing the new window if it is already open using
    the code below, but to no avail. It seems the typeof(MapWindo w) is always
    undefined. The function is in a .js file. Is it all right to declare global
    variables in a .js file?

    Any help much appreciated.

    var MapWindow;
    function OpenMapWindow(s rc, vwidth, vheight)
    {
    if(typeof(MapWi ndow) != "undefined" && MapWindow.close d == false)
    {
    MapWindow.close ();
    }
    MapWindow = window.open(src , "NewWindow" , "width=" + vwidth + ",height=" +
    vheight +
    ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
    MapWindow.focus ();
    }


  • ASM

    #2
    Re: Close a window if it is already open

    Roger Withnell wrote:[color=blue]
    > I open a new window from the current window to display maps.
    >
    > Several maps of different sizes can be displayed. The function is given the
    > size of the map and adjusts the window size accordingly.
    >
    > If a new window is already open, the new map sizes are ignored and the new
    > map is is either too small for the existing "new" window or too big, which
    > is a more serious problem!
    >
    > I've tried to fix this by closing the new window if it is already open using
    > the code below, but to no avail. It seems the typeof(MapWindo w) is always
    > undefined. The function is in a .js file. Is it all right to declare global
    > variables in a .js file?
    >
    > Any help much appreciated.
    >
    > var MapWindow;
    > function OpenMapWindow(s rc, vwidth, vheight)
    > {
    > if(typeof(MapWi ndow) != "undefined" && MapWindow.close d == false)
    > {
    > MapWindow.close ();
    > }
    > MapWindow = window.open(src , "NewWindow" , "width=" + vwidth + ",height=" +
    > vheight +
    > ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
    > MapWindow.focus ();
    > }[/color]

    var MapWindow=null;
    function OpenMapWindow(s rc, vwidth, vheight) (
    if(MapWindow || !MapWindow.clos ed) MapWindow.close ();
    MapWindow=windo w.open(src,'',' width='+vwidth+ ',height='+vhei ght+',top=100,l eft=10');
    }


    --
    Stephane Moriaux et son [moins] vieux Mac

    Comment

    • RobG

      #3
      Re: Close a window if it is already open

      ASM wrote:[color=blue]
      > Roger Withnell wrote:
      >[color=green]
      >> I open a new window from the current window to display maps.
      >>
      >> Several maps of different sizes can be displayed. The function is
      >> given the size of the map and adjusts the window size accordingly.
      >>
      >> If a new window is already open, the new map sizes are ignored and the
      >> new map is is either too small for the existing "new" window or too
      >> big, which is a more serious problem!
      >>
      >> I've tried to fix this by closing the new window if it is already open
      >> using the code below, but to no avail. It seems the typeof(MapWindo w)
      >> is always undefined. The function is in a .js file. Is it all right
      >> to declare global variables in a .js file?
      >>
      >> Any help much appreciated.
      >>
      >> var MapWindow;
      >> function OpenMapWindow(s rc, vwidth, vheight)
      >> {
      >> if(typeof(MapWi ndow) != "undefined" && MapWindow.close d == false)
      >> {
      >> MapWindow.close ();
      >> }
      >> MapWindow = window.open(src , "NewWindow" , "width=" + vwidth +
      >> ",height=" + vheight +
      >> ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
      >> MapWindow.focus ();
      >> }[/color]
      >
      >
      > var MapWindow=null;
      > function OpenMapWindow(s rc, vwidth, vheight) (
      > if(MapWindow || !MapWindow.clos ed) MapWindow.close ();[/color]

      Ooops? Try:

      if(MapWindow && !MapWindow.clos ed) MapWindow.close ();
      ---------------^^
      [color=blue]
      > MapWindow=windo w.open(src,'',' width='+vwidth+ ',height='+vhei ght+',top=100,l eft=10');
      >
      > }[/color]

      To the OP:

      You'll get gripes about the usability of non-resizable windows without
      scrollbars.

      Try this reference:

      <URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref7 6.html>

      There are many usability issues with opening new windows, it should be
      avoided as much as possible. Do not try to prevent users from re-sizing
      the window themselves - most browsers will stop you from enforcing this
      anyway.

      You should allow the user to decide where the link opens - what if they
      want it to open in a tab instead?



      --
      Rob

      Comment

      • Roger Withnell

        #4
        Re: Close a window if it is already open

        Thanks for this but still can't get it to close the window if it is open.

        Tried your code and changed it slightly as follows:

        function OpenMapWindow(s rc, vwidth, vheight)
        {
        if(MapWindow != null)
        {
        if(MapWindow.cl osed == false)
        {
        MapWindow.close ();
        }
        }
        alert(MapWindow );
        MapWindow = window.open(src , "NewWindow" , "width=" + vwidth + ",height=" + vheight + ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
        MapWindow.focus ();
        }

        The alert always gives MapWindow = null.

        Any ideas?

        "ASM" <stephanemoriau x.NoAdmin@wanad oo.fr.invalid> wrote in message news:4330a057$0 $17223$8fcfb975 @news.wanadoo.f r...[color=blue]
        > Roger Withnell wrote:[color=green]
        >> I open a new window from the current window to display maps.
        >>
        >> Several maps of different sizes can be displayed. The function is given the
        >> size of the map and adjusts the window size accordingly.
        >>
        >> If a new window is already open, the new map sizes are ignored and the new
        >> map is is either too small for the existing "new" window or too big, which
        >> is a more serious problem!
        >>
        >> I've tried to fix this by closing the new window if it is already open using
        >> the code below, but to no avail. It seems the typeof(MapWindo w) is always
        >> undefined. The function is in a .js file. Is it all right to declare global
        >> variables in a .js file?
        >>
        >> Any help much appreciated.
        >>
        >> var MapWindow;
        >> function OpenMapWindow(s rc, vwidth, vheight)
        >> {
        >> if(typeof(MapWi ndow) != "undefined" && MapWindow.close d == false)
        >> {
        >> MapWindow.close ();
        >> }
        >> MapWindow = window.open(src , "NewWindow" , "width=" + vwidth + ",height=" +
        >> vheight +
        >> ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
        >> MapWindow.focus ();
        >> }[/color]
        >
        > var MapWindow=null;
        > function OpenMapWindow(s rc, vwidth, vheight) (
        > if(MapWindow || !MapWindow.clos ed) MapWindow.close ();
        > MapWindow=windo w.open(src,'',' width='+vwidth+ ',height='+vhei ght+',top=100,l eft=10');
        > }
        >
        >
        > --
        > Stephane Moriaux et son [moins] vieux Mac
        >[/color]

        Comment

        • Dr Clue

          #5
          Re: Close a window if it is already open

          Roger Withnell wrote:[color=blue]
          > Thanks for this but still can't get it to close the window if it is open.
          > Tried your code and changed it slightly as follows:
          >
          > function OpenMapWindow(s rc, vwidth, vheight)
          > {
          > if(MapWindow != null)
          > {
          > if(MapWindow.cl osed == false)
          > {
          > MapWindow.close ();
          > }
          > }
          > alert(MapWindow );
          > MapWindow = window.open(src , "NewWindow" , "width=" + vwidth +
          > ",height=" + vheight +
          > ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
          > MapWindow.focus ();
          > }
          > The alert always gives MapWindow = null.
          >
          > Any ideas?[/color]


          1.) The alert(MapWindow ) came before the MapWindow was assigned
          so that would keep it from working the first time through

          2.) self.MapWindow would probably work better than just MapWindow
          so that it would be their the second time through

          3.) If your calling this function from the opened window, keep in mind
          that the path to the variable would end up being something like
          window.opener.M apWindow as opposed to self.MapWindow,
          which script calls from inside the opener window would use




          --
          --.
          --=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
          --=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
          --=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
          --.

          Comment

          • Christopher Benson-Manica

            #6
            Re: Close a window if it is already open

            RobG <rgqld@iinet.ne t.au> wrote:
            [color=blue]
            > There are many usability issues with opening new windows, it should be
            > avoided as much as possible. Do not try to prevent users from re-sizing
            > the window themselves - most browsers will stop you from enforcing this
            > anyway.[/color]

            Will they? My experience has been that common browsers do respect the
            programmer's wishes in this respect. I'm not claiming that it's a
            good idea, of course.
            [color=blue]
            > You should allow the user to decide where the link opens - what if they
            > want it to open in a tab instead?[/color]

            Then they're either not using IE or will be dreadfully disappointed :-)

            --
            Christopher Benson-Manica | I *should* know what I'm talking about - if I
            ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

            Comment

            • ASM

              #7
              Re: Close a window if it is already open

              Roger Withnell wrote:[color=blue]
              > Thanks for this but still can't get it to close the window if it is open.
              >
              > Tried your code and changed it slightly as follows:
              >
              > function OpenMapWindow(s rc, vwidth, vheight)
              > {
              > if(MapWindow != null)
              > {
              > if(MapWindow.cl osed == false)
              > {
              > MapWindow.close ();
              > }
              > }
              > alert(MapWindow );
              > MapWindow = window.open(src , "NewWindow" , "width=" + vwidth + ",height=" + vheight + ",left=100,top= 100,resizable=n o,toolbar=no,sc rollbars=no,men ubar=no");
              > MapWindow.focus ();
              > }
              >
              > The alert always gives MapWindow = null.[/color]

              try with

              MapWindow = false;

              function OpenMapWindow(s rc, vwidth, vheight) {
              if(MapWindow != false && MapWindow.close d == false)
              MapWindow.close ();
              alert(MapWindow ); // would allways have to say : 'false' (or undefined ?)
              MapWindow = wind .....

              step 1 : MapWindow is false -> alert says 'false' -> popup opens
              step 2 : MapWindow is a popup (so MapWindow is not false)
              step 3 : re-open popup yet opened
              MapWindow is not false and window MapWindow not closed
              step 4 : popup MapWindow is closed -> MapWindow is undefined
              -> alert says 'undefined'

              I prefer to use :

              function OpenMapWindow(s rc, vwidth, vheight) {
              if(MapWindow && !MapWindow.clos ed) MapWindow.close ();

              which means :
              if MapWindow is something and popup MapWindow is not closed
              then close popup MapWindow

              Did you read what RobG said ?

              Stephane Moriaux et son [moins] vieux Mac

              Comment

              • Richard Cornford

                #8
                Re: Close a window if it is already open

                Christopher Benson-Manica wrote:[color=blue]
                > RobG <rgqld@iinet.ne t.au> wrote:
                >[color=green]
                >> There are many usability issues with opening new windows,
                >> it should be avoided as much as possible. Do not try to
                >> prevent users from re-sizing the window themselves - most
                >> browsers will stop you from enforcing this anyway.[/color]
                >
                > Will they? My experience has been that common browsers do
                > respect the programmer's wishes in this respect. I'm not
                > claiming that it's a good idea, of course.[/color]

                Your impression is probably the result of not looking very hard. There
                are no desktop browsers on which the user's desire to prevent the
                re-sizing of a window cannot be enforced (because it can be enforced by
                external software). The same goes for all 'chrome' specifications. Many
                browsers also provide a configurable setting that prevents window
                re-sizing (either enabled or disabled by default, depending on the
                browser). I believe this even extends to the latest SP for IE.
                [color=blue][color=green]
                >> You should allow the user to decide where the link opens - what if
                >> they want it to open in a tab instead?[/color]
                >
                > Then they're either not using IE[/color]

                Microsoft's Windows IE browsers is capable of being embedded in other
                applications, and there are a number of applications that represent
                alternative GUI styles of web browsers that employ the IE web browser
                control as the display device. These include tabbed browsers (and they
                cannot easily be distinguished form any 'normal' version of IE (because
                they pretty much are)).
                [color=blue]
                > or will be dreadfully disappointed[/color]

                In an e-commerce context disappointing the user is not a particularly
                profitable practice.

                Richard.


                Comment

                • ASM

                  #9
                  Re: Close a window if it is already open

                  Richard Cornford wrote:[color=blue]
                  > Christopher Benson-Manica wrote:
                  >[color=green]
                  >>RobG <rgqld@iinet.ne t.au> wrote:
                  >>
                  >>Will they? My experience has been that common browsers do
                  >>respect the programmer's wishes in this respect. I'm not
                  >>claiming that it's a good idea, of course.[/color]
                  >
                  > Your impression is probably the result of not looking very hard. There
                  > are no desktop browsers on which the user's desire to prevent the
                  > re-sizing of a window cannot be enforced (because it can be enforced by
                  > external software). The same goes for all 'chrome' specifications. Many
                  > browsers also provide a configurable setting that prevents window
                  > re-sizing (either enabled or disabled by default, depending on the
                  > browser). I believe this even extends to the latest SP for IE.[/color]

                  If some users did set their browser in so much incapabilities
                  become their own problem : they will not get this so pretty window
                  exactly decorated, sized an positioned all for their alone own comfort.
                  It is very sad, but they'll get the last photo of nose of grand ma'
                  somewhere lost in their ugly tab of their horrible chromed from dead
                  browser with no other opportunity to come back to main and so exciting
                  context content of this marvelous site they have hardly found without
                  pushing their back button or changing tab view.

                  Seriously, on my idea, it is not worse than domly threw large divs
                  flashing over main context the visitor can't (or don't know how to)
                  close or put away.

                  There are so many way to annoy visitor
                  a little popup will not be worst.
                  [color=blue]
                  > Microsoft's Windows IE browsers is capable of being embedded in other
                  > applications,[/color]

                  and other applications can be embedded in browsers
                  and the snake bites its tail.
                  [color=blue]
                  > and there are a number of applications that represent
                  > alternative GUI styles of web browsers that employ the IE web browser
                  > control as the display device. These include tabbed browsers (and they
                  > cannot easily be distinguished form any 'normal' version of IE (because
                  > they pretty much are)).[/color]

                  What that has to see with to close a window ?
                  [color=blue][color=green]
                  >>or will be dreadfully disappointed[/color]
                  >
                  > In an e-commerce context disappointing the user is not a particularly
                  > profitable practice.[/color]

                  Buyers are yet well educated ...

                  In some e-commerce zoom on articles does in popup
                  You can see both detail and description without having
                  to tab right/left as a mad person
                  I don't think buyers already knocked out by Christmas tree
                  presentation will leave the site if they have been able
                  to accept all these flashing advertisements
                  only for a nice popup ...


                  --
                  Stephane Moriaux et son [moins] vieux Mac

                  Comment

                  • Richard Cornford

                    #10
                    Re: Close a window if it is already open

                    ASM wrote:
                    <snip>[color=blue]
                    > If some users did set their browser in so much incapabilities
                    > become their own problem : they will not get this so
                    > pretty window exactly decorated, sized an positioned all
                    > for their alone own comfort.[/color]
                    [color=blue]
                    > It is very sad, but they'll get the last photo of nose of
                    > grand ma' somewhere lost in their ugly tab of their horrible
                    > chromed from dead browser with no other opportunity to come
                    > back to main and so exciting context content of this
                    > marvelous site they have hardly found without pushing their
                    > back button or changing tab view.
                    >
                    > Seriously, on my idea, it is not worse than domly threw
                    > large divs flashing over main context the visitor can't
                    > (or don't know how to) close or put away.
                    >
                    > There are so many way to annoy visitor
                    > a little popup will not be worst.[/color]
                    [color=blue]
                    > and other applications can be embedded in browsers
                    > and the snake bites its tail.[/color]
                    [color=blue]
                    > What that has to see with to close a window ?[/color]
                    [color=blue]
                    > Buyers are yet well educated ...
                    >
                    > In some e-commerce zoom on articles does in popup
                    > You can see both detail and description without having
                    > to tab right/left as a mad person I don't think
                    > buyers already knocked out by Christmas tree
                    > presentation will leave the site if they have been
                    > able to accept all these flashing advertisements
                    > only for a nice popup ...[/color]

                    I don't want to discourage you from attempting to write in English, but
                    here you have failed.

                    Richard.


                    Comment

                    • ASM

                      #11
                      Re: Close a window if it is already open

                      Richard Cornford wrote:[color=blue]
                      > ASM wrote:
                      >
                      > I don't want to discourage you from attempting to write in English, but
                      > here you have failed.[/color]

                      My english is so ugly ?
                      or
                      did I understand nothing (anything?) ?


                      --
                      Stephane Moriaux et son [moins] vieux Mac

                      Comment

                      • RobG

                        #12
                        Re: Close a window if it is already open

                        ASM wrote:[color=blue]
                        > Richard Cornford wrote:
                        >[color=green]
                        >> ASM wrote:
                        >>
                        >> I don't want to discourage you from attempting to write in English, but
                        >> here you have failed.[/color]
                        >
                        >
                        > My english is so ugly ?
                        > or
                        > did I understand nothing (anything?) ?
                        >
                        >[/color]

                        We got the gist of it Stephane - but arguing that pop-ups are OK because
                        there are worse things foisted upon surfers is not really the point.

                        I may think TB is less severe than cancer, but I'd rather have neither.


                        --
                        Rob

                        Comment

                        • Christopher Benson-Manica

                          #13
                          Re: Close a window if it is already open

                          Richard Cornford <Richard@litote s.demon.co.uk> wrote:
                          [color=blue]
                          > Your impression is probably the result of not looking very hard. There
                          > are no desktop browsers on which the user's desire to prevent the
                          > re-sizing of a window cannot be enforced (because it can be enforced by
                          > external software). The same goes for all 'chrome' specifications. Many
                          > browsers also provide a configurable setting that prevents window
                          > re-sizing (either enabled or disabled by default, depending on the
                          > browser). I believe this even extends to the latest SP for IE.[/color]

                          I had forgotten about those user-configurable settings.

                          --
                          Christopher Benson-Manica | I *should* know what I'm talking about - if I
                          ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

                          Comment

                          • Richard Cornford

                            #14
                            Re: Close a window if it is already open

                            ASM wrote:[color=blue]
                            > Richard Cornford wrote:[color=green]
                            >> I don't want to discourage you from attempting to write
                            >> in English, but here you have failed.[/color]
                            >
                            > My english is so ugly ?
                            > or
                            > did I understand nothing (anything?) ?[/color]

                            I cannot say how much you understood. I can say that your post did not
                            convey much meaning. My impression is that it suffered from being too
                            much of a word-for-word translation from a French original containing
                            idioms that do not lend themselves to that sort of treatment.

                            For example, I observer the use of the words "the last photo of nose of
                            grand ma'", and you have previously used the phrase "last photo of my
                            mother in law". I suspect that these forms of words have more
                            significance in French, but it is in French culture that they find their
                            significance and the meaning is lost in a direct word-for-word
                            translation into English.

                            I asked one of my French colleagues if he could shed any light on this,
                            but he could not. I think he was also slightly baffled by your post.
                            However, we had a discussion about French and English idioms and the
                            problems of translating between the two. It is surprising how many
                            French and English proverbs and saying are amenable to a virtually
                            word-for-word translation, such as "it is as plain as the nose on your
                            face", which is nearly identical in French (the same words expressing
                            the same concept).

                            On the other hand, there are plenty of expressions of particular
                            concepts used in French that do not have a similar meaning once directly
                            translated into English. My colleague suggested the example:-

                            Ne batis pas de chateaux en Espagne.

                            - translated as:-

                            Don't build castles in Spain.

                            - apparently as an expression of worthless/pointless activity (if I
                            understood correctly). The English translation of the phrase, while easy
                            to understand as such, carries no such connotations. Stating "Don't
                            build castles in Spain" to a British native would be likely to result in
                            bewilderment.

                            We could not agree on an English expression that would be a precise
                            translation of the concept expressed by "Ne batis pas de chateaux en
                            Espagne", but it seems that the common saying:-

                            Don't carry coals to Newcastle.

                            - (and variations on the theme) might be acceptably close. Newcastle
                            being the first major centre of coal mining in England, and so the last
                            place to which it was worthwhile to take coal. And so possibly a similar
                            expression of worthless/pointless activity. Though it is possible that
                            it is not an appropriate expression when translating French into North
                            American or Australian English.

                            Richard.


                            Comment

                            • Richard Cornford

                              #15
                              Re: Close a window if it is already open

                              Christopher Benson-Manica wrote:[color=blue]
                              > Richard Cornford wrote:[/color]
                              <snip>[color=blue][color=green]
                              >> ... . Many browsers also provide a configurable setting
                              >> that prevents window re-sizing (either enabled or disabled
                              >> by default, depending on the browser). ...[/color][/color]
                              <snip>[color=blue]
                              > I had forgotten about those user-configurable settings.[/color]

                              That doesn't seem like a good idea in our context as even the simplest
                              scriptable browser has many user configurable permutations that will
                              directly impact upon the operation of scripts.

                              Richard.


                              Comment

                              Working...