Finding the Host name on a particular window?

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

    Finding the Host name on a particular window?

    Hi,
    I have a web application that operates on several windows. Each window
    is named win_1, win_2, win_3,... . When I quit a session, I usually
    loop through all the windows and close one by one. So far so good
    until my client wants to surf on 1 particular window and doesn't want
    that window to close when a I quit a session.
    I had something in mind:
    find the window url through "window.locatio n.host" or something (I'd
    save it as a global variable) and when I loop through my windows to
    quit one by one, I thought I'd compare their host and if it is not
    equal, I leave it open. I'm using the following codes at the moment:
    _______________ __________
    for($i=2;$i<=$w indow_number;$i ++) {
    $str = "if (window.parent. name != 'win_'".$i."') {window.open
    ('','win_'".$i. "').close() ;}";
    echo $str;
    }
    .....
    echo "if (window.parent. name != 'win_1'){window .parent.close() ;}";
    _______________ __________

    Suppose win_3 has url "www.google.com ", how can I retrieve the host
    name of win_3? Is it possible? Is there any easy way without having
    recourse to major changes? I appreciate any suggestions.
    Kind regards
    Bils
  • Rico Huijbers

    #2
    Re: Finding the Host name on a particular window?

    Bilal wrote:[color=blue]
    > Hi,
    > I have a web application that operates on several windows. Each window
    > is named win_1, win_2, win_3,... . When I quit a session, I usually
    > loop through all the windows and close one by one. So far so good
    > until my client wants to surf on 1 particular window and doesn't want
    > that window to close when a I quit a session.
    > I had something in mind:
    > find the window url through "window.locatio n.host" or something (I'd
    > save it as a global variable) and when I loop through my windows to
    > quit one by one, I thought I'd compare their host and if it is not
    > equal, I leave it open. I'm using the following codes at the moment:
    > _______________ __________
    > for($i=2;$i<=$w indow_number;$i ++) {
    > $str = "if (window.parent. name != 'win_'".$i."') {window.open
    > ('','win_'".$i. "').close() ;}";
    > echo $str;
    > }
    > ....
    > echo "if (window.parent. name != 'win_1'){window .parent.close() ;}";
    > _______________ __________
    >
    > Suppose win_3 has url "www.google.com ", how can I retrieve the host
    > name of win_3? Is it possible? Is there any easy way without having
    > recourse to major changes? I appreciate any suggestions.
    > Kind regards
    > Bils[/color]

    Well, window.location .href will give you the URL of the page that is
    displayed in the given window. So I suppose you could substring search
    it, e.g:

    if (window.locatio n.href.indexOf( 'www.myhost.com ') >= 0) {
    // ...close window...
    }

    But, without further knowing what you want to do, I find the notion of a
    multi-window web application rather ill-conceived. Are you sure you need
    multiple windows and if so, couldn't you just use frames?

    -Rico

    Comment

    • Randy Webb

      #3
      Re: Finding the Host name on a particular window?

      Bilal wrote:[color=blue]
      > Hi,
      > I have a web application that operates on several windows. Each window
      > is named win_1, win_2, win_3,... . When I quit a session, I usually
      > loop through all the windows and close one by one. So far so good
      > until my client wants to surf on 1 particular window and doesn't want
      > that window to close when a I quit a session.
      > I had something in mind:
      > find the window url through "window.locatio n.host" or something (I'd
      > save it as a global variable) and when I loop through my windows to
      > quit one by one, I thought I'd compare their host and if it is not
      > equal, I leave it open. I'm using the following codes at the moment:
      > _______________ __________
      > for($i=2;$i<=$w indow_number;$i ++) {
      > $str = "if (window.parent. name != 'win_'".$i."') {window.open
      > ('','win_'".$i. "').close() ;}";
      > echo $str;
      > }
      > .....
      > echo "if (window.parent. name != 'win_1'){window .parent.close() ;}";
      > _______________ __________
      >
      > Suppose win_3 has url "www.google.com ", how can I retrieve the host
      > name of win_3?[/color]

      You can't, unles win_3's URL is in your domain. Its a cross domain
      security issue.
      [color=blue]
      > Is it possible?[/color]

      Fortunately, no.
      [color=blue]
      > Is there any easy way without having recourse to major changes?[/color]

      Not really.
      [color=blue]
      > I appreciate any suggestions.[/color]

      Determine why you need 3+ windows open for your app to work, and then
      work backwards and make it work within one window.


      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • Randy Webb

        #4
        Re: Finding the Host name on a particular window?

        Rico Huijbers wrote:

        <--snip-->
        [color=blue]
        >
        >
        > Well, window.location .href will give you the URL of the page that is
        > displayed in the given window. So I suppose you could substring search
        > it, e.g:
        >
        > if (window.locatio n.href.indexOf( 'www.myhost.com ') >= 0) {
        > // ...close window...
        > }[/color]

        That will work, if and only if, its in the same domain as the page
        calling it. Otherwise, its a cross-domain security issue.

        But, location.hostna me is what the OP's after.




        --
        Randy
        Chance Favors The Prepared Mind
        comp.lang.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • Matt Kruse

          #5
          Re: Finding the Host name on a particular window?

          Bilal wrote:[color=blue]
          > Suppose win_3 has url "www.google.com ", how can I retrieve the host
          > name of win_3? Is it possible?[/color]

          No. Javascript security prohibits you from seeing anything about a window
          which is not in the same domain as the one the code is running in. If you
          try to get the href of a window which is at google.com, you'll get a
          run-time error. You can trap this if you'd like, and continue on to the next
          window.

          --
          Matt Kruse
          Javascript Toolbox: http://www.mattkruse.com/javascript/


          Comment

          • Default User

            #6
            Re: Finding the Host name on a particular window?

            Rico Huijbers wrote:[color=blue]
            >
            > Bilal wrote:[color=green]
            > > Hi,
            > > I have a web application that operates on several windows. Each window
            > > is named win_1, win_2, win_3,... . When I quit a session, I usually
            > > loop through all the windows and close one by one. So far so good
            > > until my client wants to surf on 1 particular window and doesn't want
            > > that window to close when a I quit a session.[/color][/color]

            [color=blue]
            > But, without further knowing what you want to do, I find the notion of a
            > multi-window web application rather ill-conceived.[/color]

            That's good advice. Most people don't like web sites opening up a bunch
            of new windows.
            [color=blue]
            > Are you sure you need
            > multiple windows and if so, couldn't you just use frames?[/color]


            Ugh. Frames are not the solution to anything. The application should
            move naturally from content page to content page as needed.




            Brian Rodenborn

            Comment

            • Matt Kruse

              #7
              Re: Finding the Host name on a particular window?

              Default User wrote:[color=blue]
              > Ugh. Frames are not the solution to anything. The application should
              > move naturally from content page to content page as needed.[/color]

              That's fine in most situations, but not always the best solution :)

              --
              Matt Kruse
              Javascript Toolbox: http://www.mattkruse.com/javascript/


              Comment

              • Chung Leong

                #8
                Re: Finding the Host name on a particular window?

                "Randy Webb" <hikksnotathome @aol.com> wrote in message
                news:yJmdnYCeJ5 5tvy_d4p2dnA@co mcast.com...[color=blue]
                > Bilal wrote:[color=green]
                > > Hi,
                > > I have a web application that operates on several windows. Each window
                > > is named win_1, win_2, win_3,... . When I quit a session, I usually
                > > loop through all the windows and close one by one. So far so good
                > > until my client wants to surf on 1 particular window and doesn't want
                > > that window to close when a I quit a session.
                > > I had something in mind:
                > > find the window url through "window.locatio n.host" or something (I'd
                > > save it as a global variable) and when I loop through my windows to
                > > quit one by one, I thought I'd compare their host and if it is not
                > > equal, I leave it open. I'm using the following codes at the moment:
                > > _______________ __________
                > > for($i=2;$i<=$w indow_number;$i ++) {
                > > $str = "if (window.parent. name != 'win_'".$i."') {window.open
                > > ('','win_'".$i. "').close() ;}";
                > > echo $str;
                > > }
                > > .....
                > > echo "if (window.parent. name != 'win_1'){window .parent.close() ;}";
                > > _______________ __________
                > >
                > > Suppose win_3 has url "www.google.com ", how can I retrieve the host
                > > name of win_3?[/color]
                >
                > You can't, unles win_3's URL is in your domain. Its a cross domain
                > security issue.[/color]

                But for the same reason close() won't on that window either. Thus the stated
                problem doesn't actually exist--not in Internet Explorer anyway.


                Comment

                Working...