从父页面滚动iframe [英] scroll an iframe from parent page
问题描述
我创建了两个网页,一个包含iframe中的另一个网页。我想通过javascript从父页面滚动嵌入页面。
I have created two webpages, one contains the other in an iframe. I would like to scroll the embedded page from the parent page via javascript.
到目前为止我尝试过:
-
$('#go')。scrollTop(200);
$(' .footer')。scrollTop(200);
var frame = document.getElementById('go ');
frame.contentWindow.scrollTo(0,200);
这些都不起作用
父网页html:
<html>
<body>
.
.
.
<div class="footer">
<iframe id="go" src="go.html"></iframe>
</div>
</body>
</html>
这两个网页都是计算机上的本地文件,我使用的是带有 - 允许的Google Chrome -file-access-from-filesflag。
Both of these webpages are local files on the computer and I am using Google chrome with "--allow-file-access-from-files" flag.
如何将iframe滚动到某个位置?
How do I scroll the iframe to a certain position?
推荐答案
这有效:
document.getElementById("go").contentWindow.setTimeout("this.scrollTo(0, 200);",1);
更新。卫生署。仅适用于IE浏览器,但我认为有一些东西。
Update. Doh. Works in IE only, but I think there's something there.
更新2 这普遍适用:
document.getElementById("go").onload = function () { this.contentWindow.scrollTo(0, 200) };
您必须等待iframe内容完成加载才能使scrollTo正常工作。
You have to wait for iframe content to finish loading for scrollTo to work.
这篇关于从父页面滚动iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!