我无法使此代码工作,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>
CN有人帮我解决这个问题,我有点卡住了
您是否可以访问 iframe 中的代码? 我相信您需要在 iframe 代码本身中设置 scrollTop。
例如:
$("body").scrollTop(100);
编辑:在此处查找更多信息: 如何获得滚动 iframe 顶部
要截获的 onLoad 事件应该是来自 iframe 本身的事件,而不是来自窗口的事件。
此外,Blender的评论部分有效。
仅当在 iframe 上打开的文档与父文档属于同一域时,此设置才有效。并且使用相同的协议:
- http://domain/main.aspx as the container and http://domain/inner.aspx at the iframe is valid
- http://domain/main.aspx as the container and https://domain/inner.aspx at the iframe will be blocked
- http://domain/main.aspx as the container and http://another/inner.aspx at the frame will also be blocked
(从我的PDA发送)