Using DOM to access other windows

J

Jeff T.

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
 
L

Lasse Reichstein Nielsen

Is there any way to access a separate IE 6.0 browser process via the
Javascript DOM ?

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.otherBrowser = 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.document.body.style.backgroundColor = "red";

In browser 2:
otherBrowser.document.body.style.backgroundColor = "green";

/L
 
D

DU

Jeff said:
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,

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?
thanks.
-Jeff

Open a sub-window and dynamically DOM-insert an image:
http://www10.brinkster.com/doctorunclear/HTMLJavascriptCSS/DynamicInsertionDOMImageInPopup.html

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
 
J

Jeff T.

Hello Lasse,

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

Regards,
-Jeff
 
J

Jeff T.

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
 
L

Lasse Reichstein Nielsen

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.

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.
Any advice?

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
 
J

Jeff T.

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

Regards,
-Jeff
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top