Search

1/08/2009

Cross-Domain Communication with IFrames

window.location.hash = '' will cause browser reload,
window.location.hash = '#' won't
Cross-Domain Communication with IFrames - 不同 domain 的 parent 跟 child 透過 fragment identifier 溝通

child的js


window.onload = function() {
setInterval(function() {
var hashVal = window.location.hash.substr(1);
document.body.style.backgroundColor = hashVal;
}, 1000);
$("speedUp").onclick = function() { parent.window.location.hash = "speedUp"; }
$("slowDown").onclick = function() { parent.window.location.hash = "slowDown"; }
}

parent的js

setInterval(function() {
if (window.location.hash == "#speedUp" && liftInterval >= 60) {
liftInterval = Math.round(0.8 * liftInterval);
window.location.hash = "#";
launchLift();
}
if (window.location.hash == "#slowDown" && liftInterval < 500) {
liftInterval = Math.round(1.2 * liftInterval);
window.location.hash = "#";
launchLift();
}
}, 100);

update: ie下這個方法不work
Julien Lecomte’s Blog » Introducing CrossFrame, a Safe Communication Mechanism Across Documents and Across Domains
Cross-Domain Communication Between IFrames

沒有留言: