Cross-domain, cross-frame Javascript

Because of the cross domain security restrictions in most Javascript implementations, it's normally impossible for one HTML document to communicate with another frame, popup, or iframe unless the two pages are served from the same domain. James Burke came up with a clever solution to this problem, allowing bidirectional communication between a parent window and it's iframe or popup.

The trick is to use the fragment identifier, that portion of the url after the # which is normally used to identify a named anchor, to pass messages between the documents. Since the javascript in both documents can retreive the other window's location, and since changing the location to a new anchor doesn't involve a page refresh, the two windows can talk to eachother. It's as simple as setting an interval on each end to poll the other window's location for changes.

Cross Frame Communication with Fragment Identifiers - Link and an Example

Posted by Jason Striegel | Nov 3, 2007 09:39 PM
Web | Permalink | Comments (1) Bookmark and Share

Recent Entries

Comments

Newest comments listed first.

Posted by: works on April 10, 2008 at 11:13 PM

works

this works! I would kiss you if you weren't infected with parasites.


Leave a comment



Bloggers

Welcome to the Hacks Blog!

Brian Jepson.Brian Jepson


Jason Striegel.Jason Striegel


Philip Torrone.Phillip Torrone



See all of the books in the Hacks Series!
Advertise here.

Recent Posts

www.flickr.com
photos in Hacks More photos in Hacks