Setting focus to window

Discussion in 'Javascript' started by Guus Ellenkamp, Aug 29, 2003.

  1. 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.
     
    Guus Ellenkamp, Aug 29, 2003
    #1
    1. Advertising

  2. "Guus Ellenkamp" <> writes:

    > 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.


    I would use a function like

    function winOpenFocus(url,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 -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Aug 29, 2003
    #2
    1. Advertising

  3. 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"><font face="Arial, Helvetica,
    sans-serif"><b><a href="http://www.abnamro.com"
    onClick="MM_callJS('CompanyWindowHandle =
    winOpenFocus(\'http://www.abnamro.com\',\'GE_Company\',\'\');')"
    target="GE_Company">ABN-AMRO</a></b></font></td>


    "Lasse Reichstein Nielsen" <> schreef in bericht
    news:...
    > "Guus Ellenkamp" <> writes:
    >
    > > 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.

    >
    > I would use a function like
    >
    > function winOpenFocus(url,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 -
    > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    > 'Faith without judgement merely degrades the spirit divine.'
     
    Guus Ellenkamp, Aug 29, 2003
    #3
  4. I think I found the solution myself: the window name may not contain
    underscores.

    "Guus Ellenkamp" <> schreef in bericht
    news:binm0j$bjm$...
    > 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"><font face="Arial, Helvetica,
    > sans-serif"><b><a href="http://www.abnamro.com"
    > onClick="MM_callJS('CompanyWindowHandle =
    > winOpenFocus(\'http://www.abnamro.com\',\'GE_Company\',\'\');')"
    > target="GE_Company">ABN-AMRO</a></b></font></td>
    >
    >
    > "Lasse Reichstein Nielsen" <> schreef in bericht
    > news:...
    > > "Guus Ellenkamp" <> writes:
    > >
    > > > 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.

    > >
    > > I would use a function like
    > >
    > > function winOpenFocus(url,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 -
    > > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    > > 'Faith without judgement merely degrades the spirit divine.'

    >
    >
     
    Guus Ellenkamp, Aug 29, 2003
    #4
  5. Guus Ellenkamp

    Grant Wagner Guest

    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_callJS('CompanyWindowHandle =
    winOpenFocus(\'http://www.abnamro.com\',\'GE_Company\',\'\');');return false;"
    target="GE_Company">ABN-AMRO</a>

    Guus Ellenkamp wrote:

    > 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"><font face="Arial, Helvetica,
    > sans-serif"><b><a href="http://www.abnamro.com"
    > onClick="MM_callJS('CompanyWindowHandle =
    > winOpenFocus(\'http://www.abnamro.com\',\'GE_Company\',\'\');')"
    > target="GE_Company">ABN-AMRO</a></b></font></td>
    >
    > "Lasse Reichstein Nielsen" <> schreef in bericht
    > news:...
    > > "Guus Ellenkamp" <> writes:
    > >
    > > > 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.

    > >
    > > I would use a function like
    > >
    > > function winOpenFocus(url,name,config) {
    > > var w = window.open(url,name,config);
    > > w.focus();
    > > return w;
    > > }
    > >
    > > and then use that where you use window.open now.
    > >
    > > /L


    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html
     
    Grant Wagner, Aug 29, 2003
    #5
  6. Guus Ellenkamp

    DU Guest

    Guus Ellenkamp wrote:

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


    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:

    http://www10.brinkster.com/doctorunclear/Netscape7/Popup/PopupAndNetscape7.html#RaiseLowerSetting

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

    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Aug 29, 2003
    #6
  7. DU <> writes:

    > His window object reference needs to be a global variable, otherwise
    > it's pretty useless.


    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.

    > Working example at:
    > http://www10.brinkster.com/doctorunclear/BrowserBugsSection/Opera7Bugs/Opera7Bugs.html
    > See function OpenRequestedPopup(strUrl) in the source code.


    I made the WindowObjectReference 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 -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Aug 29, 2003
    #7
  8. Guus Ellenkamp

    DU Guest

    Lasse Reichstein Nielsen wrote:
    > DU <> writes:
    >
    >
    >>His window object reference needs to be a global variable, otherwise
    >>it's pretty useless.

    >
    >
    > 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.
    >
    >
    >>Working example at:
    >>http://www10.brinkster.com/doctorunclear/BrowserBugsSection/Opera7Bugs/Opera7Bugs.html
    >>See function OpenRequestedPopup(strUrl) in the source code.

    >
    >
    > I made the WindowObjectReference 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


    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(url,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:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Aug 30, 2003
    #8
  9. DU <> writes:

    > Then it deletes the previous window, then re-creates and re-opens it
    > again which is a very poor usage of user system resources.


    It shouldn't need to reopen it.

    > In your function
    > function winOpenFocus(url,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.


    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 -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Aug 30, 2003
    #9
  10. Guus Ellenkamp

    DU Guest

    Lasse Reichstein Nielsen wrote:
    > DU <> writes:
    >
    >
    >>Then it deletes the previous window, then re-creates and re-opens it
    >>again which is a very poor usage of user system resources.

    >
    >
    > It shouldn't need to reopen it.
    >
    >
    >>In your function
    >> function winOpenFocus(url,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.

    >
    >
    > 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.
    >


    Thank you for correcting me on this. Yes. The document is reloaded but
    the window is not recreated.

    > 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


    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Aug 30, 2003
    #10
    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. kloppie

    Setting focus to new window

    kloppie, Nov 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    502
    kloppie
    Nov 29, 2006
  2. Jason
    Replies:
    4
    Views:
    1,664
    Jason
    May 7, 2007
  3. Hayato Iriumi

    Setting Focus on Console Window

    Hayato Iriumi, Mar 10, 2008, in forum: Ruby
    Replies:
    2
    Views:
    172
    Hayato Iriumi
    Mar 25, 2008
  4. Roger
    Replies:
    3
    Views:
    359
  5. Spizzat2
    Replies:
    2
    Views:
    192
    Spizzat2
    Jan 9, 2008
Loading...

Share This Page