Link to a line in a HTML?

2019-09-05 00:39发布

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 split into sections with IDs I can link to.

Here is the page I'm talking to, id like to link to "LEVEL 46" can I do this?

I would be just as happy with another workaround such as searching for the text or anything, I assume this could be made more complicated by it being in various wrappers, assuming it was just a plain .txt file could you do it?

Edit: im not writing the web page im trying to link to a part of someone elses, so i cannot add IDs etc

6条回答
甜甜的少女心
2楼-- · 2019-09-05 01:28

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

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

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

查看更多
We Are One
3楼-- · 2019-09-05 01:31
<a href="#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.

查看更多
姐就是有狂的资本
4楼-- · 2019-09-05 01:31

No it doesn't appear to be possible.

查看更多
放荡不羁爱自由
5楼-- · 2019-09-05 01:34

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

So for your example the link would be:

   <a href="#Level46">

The heading itself would be:

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

Hope this helps.

查看更多
手持菜刀,她持情操
6楼-- · 2019-09-05 01:38

Maybe you could define an anchor for the specific line as, for example, a section element. Then you could link to that anchor.

<section name"sec1">
<a href="sec1">
查看更多
Juvenile、少年°
7楼-- · 2019-09-05 01:39

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.

查看更多
登录 后发表回答