How do I link to a specific line of text on a page using only a URL?

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

You can also do something similar with a PDF file, where you point it to page #: Link to page 6 in the pdf list. http://mises.org/journals/scholar/long.pdf#page=6

I have done a lot, and all I find is embedding the link in HTML, which is not what I need. Ideally, I would just like to send a URL that jumps to a specific line of text / selects it (just like Citebite, but without using Citebite).

+4
source share
3 answers

Depends on the situation:

1- Your own content

a. Just add the href id and then send a link to it ( http://exmaple.com/document.php#myLine )

b. . For a more advanced solution, you can go to a specific area and select 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 this function:

<?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 interesting things like highlighting text or changing CSS values ​​depending on the arguments

2-specific content

You cannot directly link to a specific line or region without extending the browser or an external service, for example CiteBite , however with some hackers you can create your own small service that displays the website and runs its own JS on it (I think, iFrames or something something like that)

+6
source

You must provide an identifier for your item. Example: <div id="footer">Footer</div> . If you go to mypage.html#footer , the browser takes you there.

If this is not your web page, look in the code, you can find the identifier element next to the desired text.

+5
source

As far as I know, you cannot do this initially without any caching, plugins or add-ons or with full control over html where you can embed anchor tags.

+3
source

Source: https://habr.com/ru/post/1485665/


All Articles