2013-10-03 2 views
0

Новое на php :)Php: Как связать URL с идентификатором, нацеленным на раздел html?

Работая над проектом блога, я хочу перемещать (отправлять) пользователей на другую страницу с конкретной (полной) записью и ее комментариями, нажимая ссылку «Комментарии» на индексной странице.

Я хочу отправить пользователя непосредственно в комментарии div. но я также должен предоставить идентификатор сообщения со ссылкой после вопросительного знака «?». Я хочу знать, где включить #comments div (html section) в url.

Заранее спасибо.

ответ

2

Вы можете использовать пустой <a> тег, чтобы сделать это:

Вставить это перед вашими комментариями <div>:

<a name="comments"></a> 

И попробуйте ввести свою страницу с тэгом # комментарий, например: http://mysite.com/example.php?postID=123#comments

0

Сначала назначьте id элементу, который вы хотите прокрутить в браузере (пользователю).

Ex.

<div id="mycomment"> 

Затем генерировать URL, который добавляемых с # и id вы выбираете.

Ex.

http://example.com/post/1/#mycomment 
0

Добавить имя в теге привязки <a name='anchor1'> и связать его с HREF помощью префикса # <a href='#anchor1'>Comment</a>

<a href="#anchor1">First</a> | 
<a href="#anchor2">Second</a> | 
<a href="#anchor3">Third</a> | 
<a href="#anchor4">Forth</a> | 
<a href="#anchor5">Fifth</a> 

<a name='anchor1'>First comment header</a> 
<p>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br></p> 

<a name='anchor2'>Second comment header</a> 
<p>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br></p> 

<a name='anchor3'>Third comment header</a> 
<p>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br></p> 

<a name='anchor4'>Fourth comment header</a> 
<p>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br></p> 

<a name='anchor5'>Fifth comment header</a> 
<p>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br></p> 

Если комментарий деталь в другой странице называют его

<a href="other_page.php#anchor1">First</a> | 
<a href="other_page.php#anchor2">Second</a> | 
<a href="other_page.php#anchor3">Third</a> | 
<a href="other_page.php#anchor4">Forth</a> | 
<a href="other_page.php#anchor5">Fifth</a> 
Смежные вопросы