Setting focus to window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guus Ellenkamp

    #1

    Setting focus to window

    I want to use a second window to link to and put new content in it and pop
    up is some link is clicked. How to set the focus to the second window if
    it's already open. With what I do now, the window stays below my main
    window.


  • Lasse Reichstein Nielsen

    #2
    Re: Setting focus to window

    "Guus Ellenkamp" <ellenkamp.guus @wolmail.nl> writes:
    [color=blue]
    > I want to use a second window to link to and put new content in it and pop
    > up is some link is clicked. How to set the focus to the second window if
    > it's already open. With what I do now, the window stays below my main
    > window.[/color]

    I would use a function like

    function winOpenFocus(ur l,name,config) {
    var w = window.open(url ,name,config);
    w.focus();
    return w;
    }

    and then use that where you use window.open now.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Guus Ellenkamp

      #3
      Re: Setting focus to window

      Thanks for the reply, but it doesn't work. I'm working with Dreamweaver.
      This is the code I get:

      <td width="21%" align="center" height="14"><fo nt face="Arial, Helvetica,
      sans-serif"><b><a href="http://www.abnamro.com "
      onClick="MM_cal lJS('CompanyWin dowHandle =
      winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');')"
      target="GE_Comp any">ABN-AMRO</a></b></font></td>


      "Lasse Reichstein Nielsen" <lrn@hotpop.com > schreef in bericht
      news:ad9s61s2.f sf@hotpop.com.. .[color=blue]
      > "Guus Ellenkamp" <ellenkamp.guus @wolmail.nl> writes:
      >[color=green]
      > > I want to use a second window to link to and put new content in it and[/color][/color]
      pop[color=blue][color=green]
      > > up is some link is clicked. How to set the focus to the second window if
      > > it's already open. With what I do now, the window stays below my main
      > > window.[/color]
      >
      > I would use a function like
      >
      > function winOpenFocus(ur l,name,config) {
      > var w = window.open(url ,name,config);
      > w.focus();
      > return w;
      > }
      >
      > and then use that where you use window.open now.
      >
      > /L
      > --
      > Lasse Reichstein Nielsen - lrn@hotpop.com
      > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      > 'Faith without judgement merely degrades the spirit divine.'[/color]


      Comment

      • Guus Ellenkamp

        #4
        Re: Setting focus to window

        I think I found the solution myself: the window name may not contain
        underscores.

        "Guus Ellenkamp" <ellenkamp.guus @wolmail.nl> schreef in bericht
        news:binm0j$bjm $1@reader1.tisc ali.nl...[color=blue]
        > Thanks for the reply, but it doesn't work. I'm working with Dreamweaver.
        > This is the code I get:
        >
        > <td width="21%" align="center" height="14"><fo nt face="Arial, Helvetica,
        > sans-serif"><b><a href="http://www.abnamro.com "
        > onClick="MM_cal lJS('CompanyWin dowHandle =
        > winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');')"
        > target="GE_Comp any">ABN-AMRO</a></b></font></td>
        >
        >
        > "Lasse Reichstein Nielsen" <lrn@hotpop.com > schreef in bericht
        > news:ad9s61s2.f sf@hotpop.com.. .[color=green]
        > > "Guus Ellenkamp" <ellenkamp.guus @wolmail.nl> writes:
        > >[color=darkred]
        > > > I want to use a second window to link to and put new content in it and[/color][/color]
        > pop[color=green][color=darkred]
        > > > up is some link is clicked. How to set the focus to the second window[/color][/color][/color]
        if[color=blue][color=green][color=darkred]
        > > > it's already open. With what I do now, the window stays below my main
        > > > window.[/color]
        > >
        > > I would use a function like
        > >
        > > function winOpenFocus(ur l,name,config) {
        > > var w = window.open(url ,name,config);
        > > w.focus();
        > > return w;
        > > }
        > >
        > > and then use that where you use window.open now.
        > >
        > > /L
        > > --
        > > Lasse Reichstein Nielsen - lrn@hotpop.com
        > > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        > > 'Faith without judgement merely degrades the spirit divine.'[/color]
        >
        >[/color]


        Comment

        • Grant Wagner

          #5
          Re: Setting focus to window

          You need to return false from the onclick event, otherwise the HREF will be
          followed and the default behaviour of the browser will take precedence.

          <a href="http://www.abnamro.com "
          onClick="MM_cal lJS('CompanyWin dowHandle =
          winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');');ret urn false;"
          target="GE_Comp any">ABN-AMRO</a>

          Guus Ellenkamp wrote:
          [color=blue]
          > Thanks for the reply, but it doesn't work. I'm working with Dreamweaver.
          > This is the code I get:
          >
          > <td width="21%" align="center" height="14"><fo nt face="Arial, Helvetica,
          > sans-serif"><b><a href="http://www.abnamro.com "
          > onClick="MM_cal lJS('CompanyWin dowHandle =
          > winOpenFocus(\' http://www.abnamro.com \',\'GE_Company \',\'\');')"
          > target="GE_Comp any">ABN-AMRO</a></b></font></td>
          >
          > "Lasse Reichstein Nielsen" <lrn@hotpop.com > schreef in bericht
          > news:ad9s61s2.f sf@hotpop.com.. .[color=green]
          > > "Guus Ellenkamp" <ellenkamp.guus @wolmail.nl> writes:
          > >[color=darkred]
          > > > I want to use a second window to link to and put new content in it and[/color][/color]
          > pop[color=green][color=darkred]
          > > > up is some link is clicked. How to set the focus to the second window if
          > > > it's already open. With what I do now, the window stays below my main
          > > > window.[/color]
          > >
          > > I would use a function like
          > >
          > > function winOpenFocus(ur l,name,config) {
          > > var w = window.open(url ,name,config);
          > > w.focus();
          > > return w;
          > > }
          > >
          > > and then use that where you use window.open now.
          > >
          > > /L[/color][/color]

          --
          | Grant Wagner <gwagner@agrico reunited.com>

          * Client-side Javascript and Netscape 4 DOM Reference available at:
          *


          * Internet Explorer DOM Reference available at:
          *
          http://msdn.microsoft.com/workshop/a...ence_entry.asp

          * Netscape 6/7 DOM Reference available at:
          * http://www.mozilla.org/docs/dom/domref/
          * Tips for upgrading JavaScript for Netscape 7 / Mozilla
          * http://www.mozilla.org/docs/web-deve...upgrade_2.html


          Comment

          • DU

            #6
            Re: Setting focus to window

            Guus Ellenkamp wrote:
            [color=blue]
            > I think I found the solution myself: the window name may not contain
            > underscores.
            >[/color]

            Nah... Window name can contain underscores. That's not your problem
            really. You need to use a global variable to store the returned window
            object reference and then make a focus() call if the window exists but
            has not been closed.

            I discussed your issue at this precise url:



            There is an interactive demo in that page. Just look for the code.

            DU
            --
            Javascript and Browser bugs:

            - Resources, help and tips for Netscape 7.x users and Composer
            - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: Setting focus to window

              DU <drunclear@hotR EMOVEmail.com> writes:
              [color=blue]
              > His window object reference needs to be a global variable, otherwise
              > it's pretty useless.[/color]

              I am not sure I understand what the problem is. Can you explain in
              more detail?

              If he tries to open a page a second time with the same name, the page
              will just open in the same window, and it will gain focus. I see no
              need for a global variable.
              [color=blue]
              > Working example at:
              > http://www10.brinkster.com/doctorunc...pera7Bugs.html
              > See function OpenRequestedPo pup(strUrl) in the source code.[/color]

              I made the WindowObjectRef erence a local variable and removed all the
              tests for it already existing ... and it still worked the same. The
              only difference is that now it doesn't check whether you are asking
              for the same URL twice.

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • DU

                #8
                Re: Setting focus to window

                Lasse Reichstein Nielsen wrote:[color=blue]
                > DU <drunclear@hotR EMOVEmail.com> writes:
                >
                >[color=green]
                >>His window object reference needs to be a global variable, otherwise
                >>it's pretty useless.[/color]
                >
                >
                > I am not sure I understand what the problem is. Can you explain in
                > more detail?
                >
                > If he tries to open a page a second time with the same name, the page
                > will just open in the same window, and it will gain focus. I see no
                > need for a global variable.
                >
                >[color=green]
                >>Working example at:
                >>http://www10.brinkster.com/doctorunc...pera7Bugs.html
                >>See function OpenRequestedPo pup(strUrl) in the source code.[/color]
                >
                >
                > I made the WindowObjectRef erence a local variable and removed all the
                > tests for it already existing ... and it still worked the same. The
                > only difference is that now it doesn't check whether you are asking
                > for the same URL twice.
                >
                > /L[/color]

                Then it deletes the previous window, then re-creates and re-opens it
                again which is a very poor usage of user system resources.
                In your function
                function winOpenFocus(ur l,name,config) {
                var w = window.open(url ,name,config);
                w.focus();
                return w;
                }

                this is what happens if the window with the same url already exists.
                DU
                --
                Javascript and Browser bugs:

                - Resources, help and tips for Netscape 7.x users and Composer
                - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: Setting focus to window

                  DU <drunclear@hotR EMOVEmail.com> writes:
                  [color=blue]
                  > Then it deletes the previous window, then re-creates and re-opens it
                  > again which is a very poor usage of user system resources.[/color]

                  It shouldn't need to reopen it.
                  [color=blue]
                  > In your function
                  > function winOpenFocus(ur l,name,config) {
                  > var w = window.open(url ,name,config);
                  > w.focus();
                  > return w;
                  > }
                  >
                  > this is what happens if the window with the same url already exists.[/color]

                  If a window with the same name already exists, the url is opened into
                  this window. The page is reloaded, even if a page with the same url is
                  already in it, that is true, but the window is not recreated. It is
                  reused.

                  Whether it is important not to reload the same URL, that is a
                  different problem, that the original poster didn't mention (and that I
                  honestly hadn't though about). To prevent this, you do need to keep
                  a copy of the URL around, either as a global variable, or as a local
                  static variable.

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • DU

                    #10
                    Re: Setting focus to window

                    Lasse Reichstein Nielsen wrote:[color=blue]
                    > DU <drunclear@hotR EMOVEmail.com> writes:
                    >
                    >[color=green]
                    >>Then it deletes the previous window, then re-creates and re-opens it
                    >>again which is a very poor usage of user system resources.[/color]
                    >
                    >
                    > It shouldn't need to reopen it.
                    >
                    >[color=green]
                    >>In your function
                    >> function winOpenFocus(ur l,name,config) {
                    >> var w = window.open(url ,name,config);
                    >> w.focus();
                    >> return w;
                    >> }
                    >>
                    >>this is what happens if the window with the same url already exists.[/color]
                    >
                    >
                    > If a window with the same name already exists, the url is opened into
                    > this window. The page is reloaded, even if a page with the same url is
                    > already in it, that is true, but the window is not recreated. It is
                    > reused.
                    >[/color]

                    Thank you for correcting me on this. Yes. The document is reloaded but
                    the window is not recreated.
                    [color=blue]
                    > Whether it is important not to reload the same URL, that is a
                    > different problem, that the original poster didn't mention (and that I
                    > honestly hadn't though about). To prevent this, you do need to keep
                    > a copy of the URL around, either as a global variable, or as a local
                    > static variable.
                    >
                    > /L[/color]

                    DU
                    --
                    Javascript and Browser bugs:

                    - Resources, help and tips for Netscape 7.x users and Composer
                    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


                    Comment

                    Working...