2012-09-30 235 views
1

我不能让这段代码工作,当iframe被刷新时,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有人帮我这个,我有点坚持

+0

你拨弄说,它应该使用MooTools的。但是你的代码调用jQuery。你的小提琴上的设置是否错误? –

+1

您无法修改框架:*不安全的JavaScript尝试从URL http://fiddle.jshell.net/_display/的框架中通过URL http://jsbin.com/aloko5访问框架。域名,协议和端口必须匹配。* – Blender

+0

我在桌面上试过它仍然无法滚动,即使它是安全的网址 – telexper

回答

0

你有iframe中获取的代码?我相信你需要在iframe代码中设置scrollTop。

例如:

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

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

0

被截获应从iframe中一个本身,而不是从窗口在onload事件。

此外,来自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发送)