我有这个简单的 html 页面,我希望它自动滚动到 iframe 的底部但是代码根本不起作用,它不会自动向下滚动 iframe, 有谁知道这有什么问题吗?
<html>
<head>
<script type="text/javascript">
function showLog() {
el = document.getElementById("log")
el.innerHTML='<iframe id="myLogFrame" name="mylog" onload="this.contentWindow.document.documentElement.scrollTop=100" src="http://yahoo.com" width="100%" height="50%" align="middle" scrolling="yes" frameborder="0"></iframe>'
el.scrollTop=el.scrollHeight
}
</script>
</head>
<body onload="showLog()"/>
test1
<div id="log" style="width:100%"><p></p>
<p></div></body></html>
</p>
最佳答案
遗憾的是,由于 Same Origin Policy,您尝试做的事情是不可能的这限制了对不在您域中的文档的任何和所有访问。
您唯一的机会是远程页面在页面底部有一个 anchor 。如果是这样,您可以链接到该 anchor 。浏览器将跳转到那里。
<iframe src="http://yahoo.com#name_of_bottom_anchor">
关于javascript - iframe 的自动滚动对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4553132/