tags:

views:

67

answers:

2

Hello,

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.

How can I do this? I am using a comment system with PHP / MySQL.

Thanks in advance,

John

+1  A: 

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

Dazarath
How would I apply the "latest_comment" to only the most recent comment?
John
You would only apply it to the very last/first comment, depending on if the comments were sorted in ascending/descending order (by date) when you queried the database. Maybe you could add some code to your original question to give a more concrete example of where you're having difficulty?
Dazarath
I posted the code in another question. I would appreciate it if you would take a look at it.
John
+1  A: 

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');
Boris Guéry