How would I jump to a point in a page using the hash or pound symbol(#) with a get variable?

1.2k Views Asked by At

I found this tutorial that explains what I want to do using html but when I echo out the code with a get variable there is no affect to the page. I would use, for example, the following code:

echo "<a href='post.php?id=".$id."#Comments'>Click here to go to the comments</a>";



echo "<a title='Comments'>Comments</a>";

I presume the problem is to do with the get variable, so would I have to end it, some how, before using the # symbol?

2

There are 2 best solutions below

2
On BEST ANSWER

The problem actually lies in your HTML, because the anchor should be parsed correctly by browsers regardless of the query string.

Page anchors use the name attribute instead of the title attribute:

<a name='Comments'>Comments</a>

You can also apply this to the id attribute of any element:

<h2 id='Comments'>Comments</h2>
0
On

To define jump-labels you have to set a name and/or id-attribute:

echo "<a title='Comments' name='Comments' id='Comments'>Comments</a>";