windows object identity

Discussion in 'Javascript' started by mikharakiri_nospaum, Apr 22, 2006.

  1. Is there a way to tell one window from another? A quick look into wndow
    object properties revealed nothing obvious. I want to keep track of
    window object identity in a hidden input widget, so that whenever user
    clones the window, I'll be able identify this and provide an extra
    session.
     
    mikharakiri_nospaum, Apr 22, 2006
    #1
    1. Advertisements

  2. Sure. If window1 == window2 yields `false', the Window objects referred to
    are different, otherwise both references point to the same Window object.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 22, 2006
    #2
    1. Advertisements

  3. Yes, but the scope is outside of Java Script environment. I want to
    save window.id or its equivalent as a text string in a hidden form
    widget that can be passed as parameter to servlet/JSP processor. Within
    the javascript on page, I prefer not to have any knowledge about the
    other browser windows.
     
    mikharakiri_nospaum, Apr 22, 2006
    #3
  4. mikharakiri_nospaum

    Randy Webb Guest

    Thomas 'PointedEars' Lahn said the following on 4/21/2006 10:51 PM:
    You really should learn to read, and comprehend, English before replying
    to a lot of the posts you reply to. Had you continued reading, and
    comprehended, the context you would have been able to give a better -
    more informed - response.

    The answer to the question is no. And you are, yet again, showing your
    immature pedantic behavior.

    Now, go ahead, use your ad hominem defense.
     
    Randy Webb, Apr 22, 2006
    #4
  5. mikharakiri_nospaum

    ASM Guest

    a écrit :
    windows names are only known by the file loaded (or at best by the window)

    I think that to refer to a (precedent) window.name in a new file loaded
    would'nt be abble to work.

    Anyway I don't understand why you need to know in witch windows files
    are displayed.
    Isn't problem of the browser or its user ?
     
    ASM, Apr 22, 2006
    #5
  6. mikharakiri_nospaum

    Touffy Guest

    I don't really understand what you intend to do with those IDs.

    First, if you want all windows with your site loaded into them to
    communicate with each other directly :

    Are your extra windows opened by JavaScript (window.open) or do you
    want to track any window opened ?

    For exemple, if the user manually opens two tabs (or windows) in his
    browser and connects to your website on both, a script in one tab will
    *never* be able to access the other directly. They could communicate
    via the server, or by sharing cookies.

    If you care only about window.open'ed windows, then the opener has a
    reference to the popup (the value returned by window.open()) and the
    popup can use window.opener to access it's opener.

    But that has nothing to do with IDs.

    Either way you could give a unique ID to each window (that's the
    session ID you're already using anyway, so no problem here, just assign
    an "id" property to the window if you want to formalize that), but of
    course this id cannot be found by getElementById().

    If the windows can access each other, then they can read each other's
    id property (I still can't begin to guess why you'd want them to do
    that). If not, too bad.
     
    Touffy, Apr 22, 2006
    #6
  7. Cloning new browser window is as simple as "Ctrl-New Window". The end
    user may continue his session from a new window as well as the old one.
    I dont want one window to be aware of the other one.. All I want from
    the script is to tell some surrogate value of the window identity. This
    could be just raw address.

    I'm kind of perplexed. Any OO programming language can output the
    reference/pointer to the object. Not in JS?
    Therefore, you refer me to the session variable in JSP (which BTW I
    don't use)? How does JSP/Servlet session behaves when I clone the
    window? (If they are different then it solves my problem)
     
    mikharakiri_nospaum, Apr 24, 2006
    #7
  8. Just tested: The session object for the cloned browser window is the
    same:-(
     
    mikharakiri_nospaum, Apr 24, 2006
    #8
  9. Each window must have a different name, so you could use the `name' property
    of Window objects.
    I have already said that you can compare Window object references against
    each other, have I not?

    But if the user opens the window, there is no reference/pointer to an object
    in JS, unless you access the Windows (or whatever) API. Browser windows
    are _not_ part of the programming language (they have been, but that was
    in the JS-on-NN/IE-only times) but of the Application Object Model the
    browser provides. It is your fault not recognizing that, not JS's.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 24, 2006
    #9
  10. How? The script

    <script>
    alert(window.name)
    </script>

    outputs blank value

    If I clone the window, the output doest change.
    OK, failing that, is there other programmtic method to distinguish
    between browser windows?
     
    mikharakiri_nospaum, Apr 24, 2006
    #10
  11. mikharakiri_nospaum

    VK Guest

    You cannot distinguish between windows from windows themselves. This
    possibility was locked from the beginning and it was even more narrowed
    over the last decade. The reason is security and privacy reasons, not
    technical issues.

    In the cloned window script will be initialized over again (current
    state is not cloned). Using this you may mark each window onload:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function mark() {
    self['$mark'] = (new Date()).getTime();
    }
    </script>
    </head>

    <body onLoad="mark()">
    <form method="post" action="">
    <input type="button" name="b001" value="Button"
    onClick="alert(self['$mark'])">
    </form>
    </body>
    </html>

    as you see any cloned window has its own $mark value.

    But as the current script state is not cloned, the subject of your
    concerns is really escaping me. On Ctrl+N user doesn't get a copy of
    the current session: it gets a "clear copy" of the page as it was on
    the first load.
     
    VK, Apr 24, 2006
    #11
  12. Unfortunately the timestamp keeps changing every time the page is
    reloaded, so it doesn't satisfy the other requrement that windows
    identity stays the same during the session in the same browser window.
    OK, that is minor terminology snag. Ctrl+N copies over the application
    state of the browser window minus Java Script state (which isn't the
    issue for my application anyway).
     
    mikharakiri_nospaum, Apr 24, 2006
    #12
  13. mikharakiri_nospaum

    VK Guest

    You cannot bulletproof track down separate windows. You may identify
    *clients* by cookies (if enabled). This is one of "disconveniences" of
    the Web same as you cannot search on local drives or write from the
    browser right to the local file (I'm talking about the default
    circumstances). Hugely disconvenient :) - but WONTFIX.

    If your solution is absolutely dependant on proper windows tracking, it
    simply means that it is not a Web solution. You either have to choose
    an appropriate Web solution, or write a web-enabled executable to
    destribute to your clients. As simple as that.

    On each Ctrl+N your script will call onload handler in the new window.
    You can mark the new window, ajax some data to the server, adjust
    cloned form field values - whatever. So I'm still missing the technical
    problem.

    No, you cannot have 100% guarantee that each new window case will be
    tracked and properly reported. If it's a must, then see the first part
    of this post.
     
    VK, Apr 24, 2006
    #13
  14. .... lacks the required `type' attribute:

    Lucky you!
    Well, you could set the property ...
    I don't know any.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 25, 2006
    #14
  15. mikharakiri_nospaum

    bgulian Guest


    As you've probably deduced by now, within the javascript environment,
    there is no way to identify browser windows. What I and my colleagues
    ended up doing was asking an ActiveX control for the window handle (IE
    only of course but unfortunately that is the requirement for this
    software). Then we stored the handle in a session cookie. It's
    incredibly complex but we can now do many things that ASP sessions did
    not let us do.

    A truly limitied answer and probably not helpful at all but a nice
    break from the guru fight.

    Bob Gulian
     
    bgulian, Apr 25, 2006
    #15
  16. Yes, there is. As I said, provided that we assume that the `name' property
    of new Windows is empty or does simply not match "our" format, it is
    possible to set that property with string format containing a unique value
    (new Date().getTime() comes to mind), and thereby identify the browser
    window (at least the Window object we are working with; that may be a tab,
    too).
    The ability to draw meaning from posted text can be an important advantage
    around here. So much for "guru fight".


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 25, 2006
    #16
  17. mikharakiri_nospaum

    Randy Webb Guest

    Thomas 'PointedEars' Lahn said the following on 4/25/2006 11:43 AM:
    No there isn't.
    And if the name property isn't set then it means nothing to you and
    breaks your "scheme".
    "it is possible"? Is that your way of defending your ludicrous idea?
    When someone says it doesn't work, you can reply that you said "It is
    possible"?

    But guess what Mr PointedEars? If the page is opened in a new *tab* then
    you have no new *window* to deal with. Do you lack the ability to
    recognize the difference? Obviously not.
    Yes, and your ability to draw the *proper* meaning from the English
    language have been proven to be faulty at best so what you "draw
    meaning" from doesn't mean a whole lot.
     
    Randy Webb, Apr 25, 2006
    #17
  18. mikharakiri_nospaum

    bgulian Guest

    And if the user clones the window as the originator of this thread
    postulated, will that name property still contain our identifier? No.
    It would probably help the cause of enlightenment if you remembered the
    original question instead of inventing your own.


    Bob Gulian
     
    bgulian, Apr 26, 2006
    #18
  19. Of course not. That is /exactly/ what makes "cloned" windows _different_
    from "original" windows. Which is /exactly/ what the OP wants.
    Pot, kettle, black. The OP wants to recognize different browser windows,
    and create a new server-side session for each new window:

    ,-<|
    | I dont want one window to be aware of the other one.. All I want from
    | the script is to tell some surrogate value of the window identity. This
    | could be just raw address.
    | [...]

    ,-<|
    | > Therefore, you refer me to the session variable in JSP (which BTW I
    | > don't use)? How does JSP/Servlet session behaves when I clone the
    | > window? (If they are different then it solves my problem)
    |
    | Just tested: The session object for the cloned browser window is the
    | same:-(

    The client-side part of it is really quite simple:

    <head>
    ...
    <script type="text/javascript">
    // you must obey the rules for window names, set by DOM Level 0, here
    if (typeof window.name != "undefined")
    {
    if (!/^_myWindow/.test(window.name))
    {
    window.name = "_mywindow" + new Date().getUTCTime();
    }
    }
    </script>
    ...
    </head>

    This will assign the Window object a new unique name when the corresponding
    window is opened (or "cloned"), and will keep that value if it is
    refreshed, or navigation happens in it. And the best part of it is that it
    works with tabs, too.[1]


    Score adjusted

    PointedEars
    ___________
    [1] tested in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2)
    Gecko/Debian-1.5.dfsg+1.5.0.2-3 Firefox/1.5.0.2
     
    Thomas 'PointedEars' Lahn, Apr 26, 2006
    #19
  20. Of course not. That is /exactly/ what makes "cloned" windows _different_
    from "original" windows. Which is /exactly/ what the OP wants.
    Pot, kettle, black. The OP wants to recognize different browser windows,
    and create a new server-side session for each new window:

    ,-<|
    | I dont want one window to be aware of the other one.. All I want from
    | the script is to tell some surrogate value of the window identity. This
    | could be just raw address.
    | [...]

    ,-<|
    | > Therefore, you refer me to the session variable in JSP (which BTW I
    | > don't use)? How does JSP/Servlet session behaves when I clone the
    | > window? (If they are different then it solves my problem)
    |
    | Just tested: The session object for the cloned browser window is the
    | same:-(

    The client-side part of it is really quite simple:

    <head>
    ...
    <script type="text/javascript">
    // you must obey the rules for window names, set by DOM Level 0, here
    if (typeof window.name != "undefined")
    {
    if (!/^_myWindow/.test(window.name))
    {
    window.name = "_mywindow" + new Date().getTime();
    }
    }
    </script>
    ...
    </head>

    This will assign the Window object a new unique name when the corresponding
    window is opened (or "cloned"), and will keep that value if it is
    refreshed, or navigation happens in it. And the best part of it is that it
    works with tabs, too.[1]


    Score adjusted

    PointedEars
    ___________
    [1] tested in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2)
    Gecko/Debian-1.5.dfsg+1.5.0.2-3 Firefox/1.5.0.2
     
    Thomas 'PointedEars' Lahn, Apr 26, 2006
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.