iframe自动滚动到底部

问题描述 投票:1回答:2

我无法使此代码生效,iframe应该在刷新iframe时自动向下滚动到底部。

FIDDLE

码:

<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>​

任何人都可以帮助我,我有点卡住了

javascript scrollbar
2个回答
0
投票

您是否可以访问iframe中的代码?我相信你需要在iframe代码本身中设置scrollTop。

例如:

$("body").scrollTop(100);

编辑:在这里查找更多信息:How to get scrollTop of an iframe


0
投票

要拦截的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发送)

© www.soinside.com 2019 - 2024. All rights reserved.