87,997
社区成员




<iframe id="test-iframe" name="test-iframe" src="child.html" scrolling="no" frameborder="0"></iframe>
<script>
window.onload = function () {
/*
* 下面两种获取节点内容的方式都可以。
* 由于 IE6, IE7 不支持 contentDocument 属性,所以此处用了通用的
* window.frames["iframe Name"] or window.frames[index]
*/
var d = window.frames["test-iframe"].document;
d.getElementsByTagName('h1')[0].innerHTML = 'pp';
alert(d.getElementsByTagName('h1')[0].firstChild.data);
}
</script>
<iframe id="test-iframe" src="http://www.yyy.com/child.html" scrolling="no" frameborder="0"></iframe>
<input type="button" value="send" onclick="sendRequest()" />
<script>
function sendRequest() {
document.getElementById('test-iframe').src += '#a';
}
var interval = window.setInterval(function(){
if(location.hash) {
alert(location.hash);
window.clearInterval(interval);
}
},1000);
</script>
子页面:
<h1>RRRRRR</h1>
<script>
var url = 'http://www.xxx.com/father.html';
oldHash = self.location.hash,
newHash,
interval = window.setInterval(function(){
newHash = self.location.hash;
if(oldHash != self.location.hash) {
document.getElementsByTagName('h1')[0].innerHTML = 'pp';
//alert(parent.location.href); //去掉这个注释,浏览器会提示无权限
parent.location.href = url + '#b';
window.clearInterval(interval);
}
},500);
</script>