0
我需要调整跨域iframe的大小以适应内容。因此,在parent.html我写这篇文章:如何调整IFRAME大小?
$(function() {
$('iframe').load(function() {
var h = null;
if (!h) {
if (location.hash.match(/^#h(\d+)/)) {
h = RegExp.$1;
$(this).css({
'height': h + 'px'
})
location.hash = ''
}
}
})
})
和child.html我写这篇文章:
$(function() {
h = 0
h = $(document).height()
console.log(h)
if (top != self) {
top.location.replace("http://parentdomain.com/#h" + h);
}
})
它工作正常时,它加载一次,但如果我点击在iframe和内容的变化链接变量h
仍然具有第一价值。如果我在新窗口中打开child.html
,var h
将会更改,但不会在iframe中。
可以修复吗?
但我得到'h'的孩子的dom准备好了。不是吗? – rsboarder
只有第一次加载完成后 –
我对jQuery了解不多,但我们已经多次使用绑定到iframe的onload事件完成:)所以每当内容发生更改时它都适合它的内容(使用ajax调用异常;) – walialu