2012-08-23 152 views
0

我有一个嵌入标签,它嵌入我的网站的另一页,我想要嵌入向下滚动。该嵌入实际上是嵌入来自另一个页面的聊天评论,我每3秒更新一次该页面,但是我希望嵌入框架滚动条在每次刷新时滚动到底部。任何JavaScript或JQuery都会很好,请帮我完成此操作,我需要将它提交到某处。刷新滚动到底部

标记

<embed id="embed" src="comments.php" width="200" height="500" border="1"/> <-- This is embed frame 

两个页面都写在PHP文件,也comments.php文件不包含任何身体/ html标记。

的comments.php

<table id="commentstable"> 
<?php 
    echo"<tr> 
     <td class='username'>$username</td> 
     <td class='comment'>$comment</td> 
      </tr>"; 
?> 
</table> 
我用这刷新评论框

和page.Only框架已经更新,但主网页是静态的。

Header("refresh:3;url='comments.php'"); 

请,我需要带脚本标记的完整代码。

回答

3

听取comments.php中的onload事件并向下滚动此事件。您可以使用jQuery:

$("window").load(scrollDown); 

使用的onload属性:

// your comment.php body tag 
<body onload="scrollDown()"> 

实际下滚功能可以是这样的:

scrollDown = function() { 
    document.body.scrollTop = document.body.scrollHeight; 
} 
0
$(function(){ 
$('body').scrollTop($(document).height()); 
});