Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 27th, 2005, 07:26 PM
Registered User
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default cross-window synchronization

I'm trying to build a small "application" where the main window (firstfile.html) loads some other HTML file into a second window, and then manipulates its content via DOM.

The straightforward approach

// firstfile.html
w.document.getElementById("p1").style.visibility=" hidden";
// ...

does not work because DOM is not ready when the second line is executed. So I tried to use the onload event of the 2nd window, attaching an event handler to it, which points to a callback function in the 1st window:

// firstfile.html
function o() { alert("secondfile loaded"); }
// ...

And now the problem:
Under Firefox and Opera, the function o() gets called as expected.
But not under the Internet Explorer.
Any ideas, what am I doing wrong, and how to get this code to work also under IE?

// I'd like to keep the secondfile.html free of scripts

Old April 28th, 2005, 03:49 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

Alternatively use a loop:
var oNewWin = window.open(....);
while (!oNewWin.document)
  //Something to pass the time here.
//carry on
Inside your loop you can do nothing, if the document can take a long time then you might want to look at using setTimeout to check for the new window.
I would have thought your code would have worked. Is the second page from the same server as the first? If not you will be forbidden access to the window and the DOM anyway by IE unless this is a "Trusted Site".


Joe (Microsoft MVP - XML)
Old April 28th, 2005, 10:10 AM
Registered User
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for the suggested alternative!

To answer your question :
Yes, the second page is even from the same folder as the first.

And that code works fine in Firefox and in Opera. But not in IE - neither with both pages on the server (defined as a "Trusted Site") nor locally.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross-domain synchronization NicoDeBruin General .NET 5 August 26th, 2007 02:34 PM
data synchronization abdulweb General .NET 0 August 26th, 2007 12:20 AM
--Javascript Synchronization-- tal Javascript 2 June 29th, 2007 11:33 AM
XML Synchronization prashant_dnmmkpk Biztalk 0 January 17th, 2005 09:16 AM
Synchronization Problem bveerendrakumar Pro VB 6 2 July 10th, 2003 05:18 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.