Focus() window by Name NOT Reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • N/A

    #1

    Focus() window by Name NOT Reference

    Hey all,

    If I open a popup like this

    window.open('ht tp://www.google.com' , 'popup', 'width = 618, height = 425,
    directories = no, location = no, menubar = no, resizable = no, scrollbars =
    yes, status = no, toolbar = no');

    Then I know that there is a window object in the windows collection called
    'popup'. So how can I make that window come to the front? Looking for
    something like windows['popup'].focus()

    I know you can set a variable to the window reference when you open the
    popup ie( var x = window.open(); ) but this is not suitable in my
    particular case. I need to be able to gain access to the window object
    without having its direct reference...

    Thanx


  • DU

    #2
    Re: Focus() window by Name NOT Reference

    N/A wrote:
    [color=blue]
    > Hey all,
    >
    > If I open a popup like this
    >
    > window.open('ht tp://www.google.com' , 'popup', 'width = 618, height = 425,
    > directories = no, location = no, menubar = no, resizable = no, scrollbars =
    > yes, status = no, toolbar = no');
    >[/color]

    You need to remove all blank spaces in the 3rd parameter string list.

    "windowFeat ures is an optional string containing a comma-separated list
    of options for the new window (do not include any spaces in this list)."


    Btw, why do you turn off the statusbar and remove the resizability of
    the popup?
    [color=blue]
    > Then I know that there is a window object in the windows collection called
    > 'popup'.[/color]

    No. That's just a property of string type; it's not a window object
    reference (pointer in memory).

    So how can I make that window come to the front? Looking for[color=blue]
    > something like windows['popup'].focus()
    >[/color]

    var WindowObjectRef erence ; // needs to be a global variable

    function OpenRequestedPo pup()
    {
    if(WindowObject Reference == null || WindowObjectRef erence.closed)
    {
    WindowObjectRef erence = window.open("ht tp://www.google.com" , "popup",
    "width=618,heig ht=425,resizabl e=yes,scrollbar s=yes,status=ye s");
    }
    else if(!WindowObjec tReference.clos ed)
    {
    WindowObjectRef erence.focus();
    };

    [color=blue]
    > I know you can set a variable to the window reference when you open the
    > popup ie( var x = window.open(); ) but this is not suitable in my
    > particular case.[/color]

    Why? Please elaborate.

    Let me underline that the successful use of focus() implies that
    javascript is enabled on the remote system. So trying to use the focus()
    method on an opened secondary window by a target attribute with js
    disabled cannot work.

    I need to be able to gain access to the window object[color=blue]
    > without having its direct reference...
    >
    > Thanx
    >
    >[/color]

    Then it's impossible. focus() is a method for a window object reference:
    therefore you need a direct reference to it, a pointer in the memory heap.

    DU
    --
    Javascript and Browser bugs:


    Comment

    • N/A

      #3
      Re: Focus() window by Name NOT Reference

      Thanks Laurent, perfect :)


      "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
      message news:3F1247D2.2 000805@bluewin_ NO_SPAM.ch...[color=blue]
      > Hi,
      >
      > N/A wrote:[color=green]
      > > Hey all,
      > >
      > > If I open a popup like this
      > >
      > > window.open('ht tp://www.google.com' , 'popup', 'width = 618, height =[/color][/color]
      425,[color=blue][color=green]
      > > directories = no, location = no, menubar = no, resizable = no,[/color][/color]
      scrollbars =[color=blue][color=green]
      > > yes, status = no, toolbar = no');
      > >
      > > Then I know that there is a window object in the windows collection[/color][/color]
      called[color=blue][color=green]
      > > 'popup'. So how can I make that window come to the front? Looking for
      > > something like windows['popup'].focus()
      > >
      > > I know you can set a variable to the window reference when you open the
      > > popup ie( var x = window.open(); ) but this is not suitable in my
      > > particular case. I need to be able to gain access to the window object
      > > without having its direct reference...
      > >
      > > Thanx[/color]
      >
      > You should always keep a reference (the 'x' in your example) to your
      > windows, but I can imagine cases where you really don't have access to
      > it. In these rare cases, you can gain a new reference to the opened
      > window with:
      >
      > var newX = open( '', 'popup', '' );
      >
      > After that, you can work with it like with a normal reference, for[/color]
      example:[color=blue]
      >
      > newX.focus();
      >
      > Note however that this will open a new blank window if popup was
      > previously closed by the user. If you don't keep a reference on this
      > window somewhere (for example in a frameset), you have no way to know it
      > the window is still open or not.
      >
      > HTH,
      >
      > Laurent
      > --
      > Laurent Bugnion, GalaSoft
      > Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
      > Private/Malaysia: http://mypage.bluewin.ch/lbugnion
      > Support children in Calcutta: http://www.calcutta-espoir.ch
      >[/color]


      Comment

      Working...