我无法使此代码工作,刷新 iframe 时,iframe 应该自动向下滚动到底部。
代码:
<html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/ujuci5/2/edit
-->
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
<p>iframe:</p>
<iframe src="http://jsbin.com/aloko5" id="frame" frameborder="0" width="200px" height="300px"></iframe>
<script>
$(window).load(function ()
{
var $contents = $('#frame').contents();
$contents.scrollTop($contents.height());
});
</script>
</body>
</html>
有人能帮我解决这个问题吗,我有点卡住了
最佳答案
您有权访问 iframe 中的代码吗?我相信您需要在 iframe 代码本身中设置scrollTop。
例如:
$("body").scrollTop(100);
编辑:在此处查找更多信息:How to get scrollTop of an iframe
关于javascript - iframe自动滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12658482/