Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

html - How to link to specific line of text in page, using only URL?

I am curious if there is a way to use only a URL to send someone to a specific line at a given page. Citebite does this, however it links to a cached page instead of the actual live page. http://citebite.com/

You can also do something similar with PDF's where you give it a designated page #: Link to page 6 in the listed pdf. http://mises.org/journals/scholar/long.pdf#page=6

I have done a lot of looking and all I am finding are for embedding the link in HTML, which isn't what I'm after. Ideally I would like to be able to just send a URL that jumps to a specific line of text/ highlights it (exactly like Citebite does, but without having to use Citebite).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Depends on the situation:

1-Your own content

a. Simply add a href id, and then send a link to that (http://exmaple.com/document.php#myLine)

b. For a more advanced solution, you can scroll to a specific area and highlight it using javascript, basically you call something like this: http://example.com/document.php?scrollX=100&scrollY=230

and in your PHP code you have a function like this:

<?php
if(isset($_GET['scrollX']) && isset($_GET['scrollY')){
    ?>
       <script type="text/javascript">
           window.scrollTo(<?= $_GET['scrollX'];?>, <?=$_GET['scrollY'];?>);
       </script>
    <?
}
?>

You can also use JQuery and do more fancy things like highlighting text or changing CSS values depending on the arguments

2-Someone else's content

You cannot directly link to a specific line or area without a browser extension or an external service like CiteBite, however with some hackery you can build your own little service that displays the website and run your own JS on it (think iFrames or something like that)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...