如何仅使用 URL 链接到页面中的特定文本行? [英] How to link to specific line of text in page, using only URL?

查看:17
本文介绍了如何仅使用 URL 链接到页面中的特定文本行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇是否有一种方法可以仅使用 URL 将某人发送到给定页面的特定行.Citebite 会这样做,但是它链接到缓存页面而不是实际的实时页面.http://citebite.com/

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/

您还可以对 PDF 执行类似操作,在其中指定指定页面 #:链接到列出的 pdf 中的第 6 页.http://mises.org/journals/scholar/long.pdf#page=6

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

我已经做了很多查找,我发现的只是将链接嵌入到 HTML 中,这不是我所追求的.理想情况下,我希望能够发送一个跳转到特定文本行/突出显示它的 URL(与 Citebite 完全一样,但不必使用 Citebite).

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

推荐答案

视情况而定:

1-您自己的内容

a. 只需添加一个 href id,然后发送一个链接(http://exmaple.com/document.php#myLine)

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

b. 对于更高级的解决方案,您可以滚动到特定区域并使用 javascript 突出显示它,基本上您可以这样调用:http://example.com/document.php?scrollX=100&scrollY=230

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

在你的 PHP 代码中,你有一个这样的函数:

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>
    <?
}
?>

您还可以使用 JQuery 来做更多奇特的事情,例如根据参数突出显示文本或更改 CSS 值

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

2-其他人的内容

如果没有浏览器扩展程序或诸如 CiteBite 之类的外部服务,您无法直接链接到特定线路或区域,但是通过一些技巧,您可以构建自己的小服务来显示网站并在其上运行您自己的 JS(想想 iFrames 或类似的东西)

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)

这篇关于如何仅使用 URL 链接到页面中的特定文本行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆