2

I'm working on comments for posts on my website. How to create a button in javascript that will open iframe window with comments when user clicks on that button? Something like Facebook have with their comments on posts. If there is a way to create this with other language I would like that you write it. I just wrote javascript because I heard that you can do that in javascript. If there is a more elegant and/or better way feel free to write it. So below every posts I would add a button and when user clicks on it, it should open something like this:

<iframe src="comment.php?postid=<?php echo $postid; ?>" 
    width=600px; 
    height=500px;>
</iframe>

And is there a way that iframe window loads only when you click on the button, not in the same time as page on which are posts? For example, if I have 10 posts on one page, and comments for all 10 posts are loading at the same time as the page with posts, it would slow down a page a lot.

Also do you know how to adjust iframe window size to amount of posts, so that if a post have 1 comment, window size is 100px, and if a posts have 5 comments, window size is 500px?

I know that Facebook have something much better than this for their comments, so if you know something better than my idea, please feel free to share it.

4

3 に答える 3

0

jquery .load、.post、.get、または .ajax

すべての記事の下に、comments という名前の div クラスがあり、その div に何も css を表示しません。ユーザーがその記事のコメント表示ボタンをクリックすると、サーバーにリクエストが送信され、その記事 ID に対するコメントが求められます。

記事の ID をビュー コメント リンクの属性に保存して、コメントが必要な記事の ID を .load リクエストに渡すことができます。

<div articleid="5" class="view-com-button">view comments</div>
<div class="comment" articleid="5" style="display:none"></div>
$(".view-com-button").click(function(event){
$(".comment[articleid='$(this).attrib("articleid").load("comment.php", {( "idarticle" : $(this).attrib("articleid") )};
});
于 2013-04-15T20:17:27.330 に答える