View Single Post
  #3 (permalink)  
Old 01-08-09, 10:17 PM
Sephr Sephr is offline
New Member
 
Join Date: Jan 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Yeroon View Post
Then you can ask for url, call events etc.

You can only access properties and events of iframe pages if they are on the same domain.
If the website the user is on is owned by the same guy who owns the first domain, he could just set up message listeners and send messages (using postMessage) to each other.
Example:
http://example.a/ sends:
Code:
SomeIframe.postMessage(
JSON.stringify({
"request-var": "location.href"
}),'http://example.b');
http://example.b/ responds:
Code:
window.onmessage = function(e) {
  if (e.origin == 'http://example.a') {
    var requestVar = JSON.parse(e.data)['request-var'];
    e.source.postMessage(JSON.stringify(window[requestVar]), e.origin);
  }
}
The code either requires a Gecko-based browser (which includes the JSON object as of 1.9.1, ie. Firefox 3.1+) or json2.js to have been loaded beforehand.

postMessage will only work in Safari 3.1.2+, Firefox 3+, and IE8 beta 2.
Reply With Quote