iframe自动滚动到底部

时间:2012-09-30 03:53:49

标签: javascript scrollbar

我无法使此代码正常工作,iframe应在刷新iframe时自动向下滚动到底部。

FIDDLE

CODE:

<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有人帮我这个,我有点卡住了

2 个答案:

答案 0 :(得分:0)

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

例如:

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

修改:点击此处查看更多信息:How to get scrollTop of an iframe

答案 1 :(得分: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发送)

相关问题