I made a comment on a Wordpress blog and I noticed that after I submitted the comment, the top of the browser was flush with the top of my comment. In other words, the web page was auto-scrolled down to the top of my comment开发者_C百科.
How can I do this? I am using a comment system with PHP / MySQL.
Thanks in advance,
John
Use an anchor and try to redirect adding the anchor to your link.
header('Location: http://www.example.com/questions/2301455#comment-54564');
should work.
Else you can do it with javascript by setting the hash property of the location object.
location.hash = '#comment-54564';
or using jQuery :
$(location).attr('hash', '#comment-54564');
You can use the following:
<a name="latest_comment">Comment goes here</a>
And then after a user posts a comment, redirect them to:
http://www.your-domain.com/your-uri#latest_comment
Check out this link under the "name attribute" section:
http://www.w3schools.com/html/html_links.asp
精彩评论