Link to a line in a HTML?

妖精的绣舞 提交于 2019-12-24 15:33:43

问题


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


回答1:


<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.




回答2:


No it doesn't appear to be possible.




回答3:


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.




回答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.




回答5:


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

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

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




回答6:


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">


来源:https://stackoverflow.com/questions/11049020/link-to-a-line-in-a-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!