Using DOM to access other windows

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

    Using DOM to access other windows

    All,

    Is there any way to access a separate IE 6.0 browser process via the
    Javascript DOM ? For example, open IE once. Open IE again (not using
    File->New). Can the second IE browser/process access the DOM objects
    of the first, if so, can someone please post a bit of sample code?

    thanks.
    -Jeff
  • Lasse Reichstein Nielsen

    #2
    Re: Using DOM to access other windows

    jeffting@hotmai l.com (Jeff T.) writes:
    [color=blue]
    > Is there any way to access a separate IE 6.0 browser process via the
    > Javascript DOM ?[/color]

    Not directly.
    One thing to notice, is that different IE windows are all using the
    same browser component, so they can theoretically communicate.

    To access another window's properties, you need a reference to that
    window. There is no direct way to find such a reference to an existing
    window.

    There is a (not so pretty) hack.
    If you open a new window with a name, i.e.,
    var w = window.open("", "windowName ");
    in both browsers, then the second to call window.open will get a reference
    to the window openend by the first.
    If the first browser stores a reference to itself in the window, the
    second can read it.

    Try this:

    In browser 1:
    var w = window.open("", "foobarbaz" );
    w.dummy = window;

    In browser 2:
    var w = window.open("", "foobarbaz" );
    otherBrowser = w.dummy;
    otherBrowser.ot herBrowser = window;
    w.close();

    After this, both browser windows have a reference to the window object
    of the other browser. Try it by, e.g., changing the background:

    In browser 1:
    otherBrowser.do cument.body.sty le.backgroundCo lor = "red";

    In browser 2:
    otherBrowser.do cument.body.sty le.backgroundCo lor = "green";

    /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

      #3
      Re: Using DOM to access other windows

      Jeff T. wrote:
      [color=blue]
      > All,
      >
      > Is there any way to access a separate IE 6.0 browser process via the
      > Javascript DOM ? For example, open IE once. Open IE again (not using
      > File->New). Can the second IE browser/process access the DOM objects
      > of the first,[/color]

      No. It's possible only and only if the "second" browser window was
      opened via javascript. Only in cases where the "second" window is a
      sub-window (also referred as secondary window or child window) created
      with the window.open() call.

      if so, can someone please post a bit of sample code?[color=blue]
      >
      > thanks.
      > -Jeff[/color]

      Open a sub-window and dynamically DOM-insert an image:


      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

      • Jeff T.

        #4
        Re: Using DOM to access other windows

        Hello Lasse,

        This worked wonders! Thank you for this piece of ingenious advice.

        Regards,
        -Jeff


        Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<isns4cv1. fsf@hotpop.com> ...[color=blue]
        > jeffting@hotmai l.com (Jeff T.) writes:
        >[color=green]
        > > Is there any way to access a separate IE 6.0 browser process via the
        > > Javascript DOM ?[/color]
        >
        > Not directly.
        > One thing to notice, is that different IE windows are all using the
        > same browser component, so they can theoretically communicate.
        >
        > To access another window's properties, you need a reference to that
        > window. There is no direct way to find such a reference to an existing
        > window.
        >
        > There is a (not so pretty) hack.
        > If you open a new window with a name, i.e.,
        > var w = window.open("", "windowName ");
        > in both browsers, then the second to call window.open will get a reference
        > to the window openend by the first.
        > If the first browser stores a reference to itself in the window, the
        > second can read it.
        >
        > Try this:
        >
        > In browser 1:
        > var w = window.open("", "foobarbaz" );
        > w.dummy = window;
        >
        > In browser 2:
        > var w = window.open("", "foobarbaz" );
        > otherBrowser = w.dummy;
        > otherBrowser.ot herBrowser = window;
        > w.close();
        >
        > After this, both browser windows have a reference to the window object
        > of the other browser. Try it by, e.g., changing the background:
        >
        > In browser 1:
        > otherBrowser.do cument.body.sty le.backgroundCo lor = "red";
        >
        > In browser 2:
        > otherBrowser.do cument.body.sty le.backgroundCo lor = "green";
        >
        > /L[/color]

        Comment

        • Jeff T.

          #5
          Re: Using DOM to access other windows

          Hi again,

          The two pages talk perfectly if they're both local html files.
          However, when I run Tomcat (a web server) on one of the pages, and the
          other page is local, I'm getting permission denied on an attempt to
          get the third dummy window.

          The JavaScript error is as follows:
          Error: Permission Denied
          on the line:
          otherBrowser = w.dummy;

          Any advice? Thanks.
          -Jeff


          jeffting@hotmai l.com (Jeff T.) wrote in message news:<1ba34b00. 0309170736.13b3 2a9b@posting.go ogle.com>...[color=blue]
          > Hello Lasse,
          >
          > This worked wonders! Thank you for this piece of ingenious advice.
          >
          > Regards,
          > -Jeff
          >
          >
          > Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<isns4cv1. fsf@hotpop.com> ...[color=green]
          > > jeffting@hotmai l.com (Jeff T.) writes:
          > >[color=darkred]
          > > > Is there any way to access a separate IE 6.0 browser process via the
          > > > Javascript DOM ?[/color]
          > >
          > > Not directly.
          > > One thing to notice, is that different IE windows are all using the
          > > same browser component, so they can theoretically communicate.
          > >
          > > To access another window's properties, you need a reference to that
          > > window. There is no direct way to find such a reference to an existing
          > > window.
          > >
          > > There is a (not so pretty) hack.
          > > If you open a new window with a name, i.e.,
          > > var w = window.open("", "windowName ");
          > > in both browsers, then the second to call window.open will get a reference
          > > to the window openend by the first.
          > > If the first browser stores a reference to itself in the window, the
          > > second can read it.
          > >
          > > Try this:
          > >
          > > In browser 1:
          > > var w = window.open("", "foobarbaz" );
          > > w.dummy = window;
          > >
          > > In browser 2:
          > > var w = window.open("", "foobarbaz" );
          > > otherBrowser = w.dummy;
          > > otherBrowser.ot herBrowser = window;
          > > w.close();
          > >
          > > After this, both browser windows have a reference to the window object
          > > of the other browser. Try it by, e.g., changing the background:
          > >
          > > In browser 1:
          > > otherBrowser.do cument.body.sty le.backgroundCo lor = "red";
          > >
          > > In browser 2:
          > > otherBrowser.do cument.body.sty le.backgroundCo lor = "green";
          > >
          > > /L[/color][/color]

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Using DOM to access other windows

            jeffting@hotmai l.com (Jeff T.) writes:
            [color=blue]
            > The two pages talk perfectly if they're both local html files.
            > However, when I run Tomcat (a web server) on one of the pages, and the
            > other page is local, I'm getting permission denied on an attempt to
            > get the third dummy window.[/color]

            Yes, the dummy window belongs to the domain of the page that opened it
            until a page is loaded into it. Cross domain scripting restrictions apply.
            [color=blue]
            > Any advice?[/color]

            If one of the pages are always local, and you are using Internet
            Explorer, you can make it an HTA-file (HTML application, look it up on
            MSDN). That gives it permission to ignore cross domain restrictions.
            You will just have to make the other page open the window.

            If you want to have it work generally, i.e., on other people's
            browsers, across domains, then my advice is to give up. Any cross
            domain scripting hole you find will be closed eventually, and
            most people will not change their default security settings to
            accomodate your page.

            /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

            • Jeff T.

              #7
              Re: Using DOM to access other windows

              I tried the HTA lead you gave me, and it proved successful, and
              sufficient for my needs. Thank you very much, Lasse.

              Regards,
              -Jeff


              Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<4qz8kb9o. fsf@hotpop.com> ...[color=blue]
              > jeffting@hotmai l.com (Jeff T.) writes:
              >[color=green]
              > > The two pages talk perfectly if they're both local html files.
              > > However, when I run Tomcat (a web server) on one of the pages, and the
              > > other page is local, I'm getting permission denied on an attempt to
              > > get the third dummy window.[/color]
              >
              > Yes, the dummy window belongs to the domain of the page that opened it
              > until a page is loaded into it. Cross domain scripting restrictions apply.
              >[color=green]
              > > Any advice?[/color]
              >
              > If one of the pages are always local, and you are using Internet
              > Explorer, you can make it an HTA-file (HTML application, look it up on
              > MSDN). That gives it permission to ignore cross domain restrictions.
              > You will just have to make the other page open the window.
              >
              > If you want to have it work generally, i.e., on other people's
              > browsers, across domains, then my advice is to give up. Any cross
              > domain scripting hole you find will be closed eventually, and
              > most people will not change their default security settings to
              > accomodate your page.
              >
              > /L[/color]

              Comment

              Working...