Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

javascript - Cross-domain hash change communication

Please consider the following two domains: domain1.com and domain2.

From domain1 I open an iframe that points to domain2.

Now, I want these guys to communicate with each other, which I've successfully accomplished by applying hash change event listeners on both domains.

That way, the hash in the parent window (domain1) will trigger if domain2 calls parent.location with a new hash. Also, the hash change event triggers in the iframe if I from the parent changes its src attribute to a new hash.

This works great!

Here comes the trouble:

The back and forward functionality in the browser gets messed up. Simply put, by creating two hash instances, the browser back button has to be clicked twice to get the parent hash to change since it has to cycle through the iframe's hash first.

How can I communicate with a cross-domain iframe 2-way without screwing up the history object?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use easyXDM, it's a javascript library that does all the hard work for you, enabling you to do cross-domain communication and RPC in all browsers, including IE6.

This will not use the HashTransport for any of the current browsers (not even IE6), and so will not change the history.

You will not find anything better..

You can read about some of its inner workings in this Script Junkie article, or go straight to the readme at github


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...