Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 27th, 2005, 08:26 PM
Registered User
 
Join Date: Apr 2005
Location: , , .
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=window.open("secondfile.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"); }
w=window.open("secondfile.html");
w.onload=o;
// ...

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

Reply With Quote
  #2 (permalink)  
Old April 28th, 2005, 04:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Alternatively use a loop:
Code:
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)
Reply With Quote
  #3 (permalink)  
Old April 28th, 2005, 11:10 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 12:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.