Skip to content Skip to sidebar Skip to footer

Link To A Line In A Html?

Is it possible to link to a line number in a html file? I want to link someone to part of a very large document which is on a webpage but the whole thing is in one tag so is not sp

Solution 1:

<ahref="#a-place-in-the-document></a>

...


<h1 id="a-place-in-the-document">There's a link to here!</h1>

The link will have the page jump to the element with the specified ID.

For example: http://example.com#hello will link to http://example.com and immediately go to the element with ID of hello.


In the case where you can't have IDs (such as in text files on gamefaqs), you'd need to provide a search string, for people to quickly search and find whatever section you need (such as [LV46]), and have your readers to search for it.

Solution 2:

No it doesn't appear to be possible.

Solution 3:

You would need to convert all of your Headings into anchor tags.

So for your example the link would be:

<ahref="#Level46">

The heading itself would be:

   <h1 id="Level46">Level 46</h1>

Hope this helps.

Solution 4:

If it is just a text file, or a collection of text files in a directory structure, you can create a parallel directory structure so people can browse

http://pdssbn.astro.umd.edu/holdings/

as

http://pdssbn.astro.umd.edu/byline/holdings/

and generate line numbers and/or anchors to individual lines on the fly, even if other non-text files are under the /holdings/ tree, with an Apache HTTPd AliasMatch like this

AliasMatch /byline/holdings/.*[.](asc|cat|lbl|tab|txt) /path/cgi-bin/pds_byline.cgi

and a symlink e.g. assuming your tree is under top/ e.g. top/holdings/,

ln -s . .../top/byline

and a simple script (cgi-bin/pds_byline.cgi above) that converts the text file to HTML on the fly. I have created a Git repo to do just that here; that is configured for Planetary Data System (PDS) data sets under http://pdssbn.astro.umd.edu/holdings/.

You would of course need access to the Apache HTTPd configuration files (/etc/httpd/conf/conf//.conf) to do this, to put in a

<Directory .../top/cgi-bin>
  AllowOverride All
</Directory>

entry to use a .htaccess file in cgi-bin/, and the AliasMatch above, at a minimum. N.B. AliasMatch cannot go into the .htaccess file.

Caveat: this only creates anchors by line number; if the file changes over time then existing links to those line numbers will be broken; you could of course do the same thing instead looking for specific text strings like "Level 46" and inserting the relevant anchors on the fly.

Solution 5:

<a name="destination" id="destination"></a>Destination anchors

<ahref="#destination">Destination anchors </a>

Source: http://www.motive.co.nz/glossary/anchor.php#destination

Post a Comment for "Link To A Line In A Html?"