Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a deeplink to a subsection of a web page?

Does anyone know how I can create a deeplink to a subsection of an individual web page?

Wiki seem to have it cracked but I can't seem to find the answers anywhere on the web.

PS: keep it simple!

like image 663
isonome Avatar asked Jan 15 '23 12:01

isonome


2 Answers

Linking to a specific location or element on a page is possible only if the destination contains markup that constitutes a “destination anchor” that you can use in a fragment identifier (starting with #) in a link. The following create such anchors:

  • An id attribute (on any element)
  • A name attribute on an a element

The former is the modern, preferable way and lets you refer to an element, not just a location (point) or just an inline element. For example, if the destination page http://www.example.com/stuff.html contains

<div class="section" id="sec7">
<h2>Foo bar</h2>
<p>Some text.</p>
Any other content
</div>

then you can use a link like

<a href="http://www.example.com/stuff.html#sec7">Foo bar</a>
like image 126
Jukka K. Korpela Avatar answered Jan 18 '23 00:01

Jukka K. Korpela


Suppose you wanted to begin a document with a table of contents that would link people to text that appear s later in the document. Your index would include the following:

<a href="#pt1">Part I</a> <a href="#pt2">Part II</a>

Later in the document, you will include the following tags:

<a name=pt1></a> and <a name=pt2></a>

Reference: Links and Anchors

EDIT:

Where ever you want to insert a link, write this:

<a href="http://yourpage.com#pt1">Part I</a> 

Here http://yourpage.com would be replaced by the actual url to your page. Now in the code for your page, insert a tag at the point that you want your link to point to.

<a name=pt1></a>
like image 34
Pulkit Goyal Avatar answered Jan 18 '23 01:01

Pulkit Goyal