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

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

问题描述

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



您也可以使用与PDF相似的东西,在指定的页面上输入#:
链接到列出的pdf中的第6页。
http://mises.org/journals/scholar/long.pdf #page = 6



我已经做了很多工作,我发现所有的东西都是嵌入HTML中的链接,之后。理想情况下,我希望能够发送跳转到特定文本行的URL /突出显示它(与Citebite完全一样,但不必使用Citebite)。

解决方案

取决于情况:

1-您自己的内容



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

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



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

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

您也可以使用JQuery并根据参数执行更高级的事情,如突出显示文本或更改CSS值

2其他人的内容 您无法直接链接到特定行或没有浏览器扩展或像 CiteBite 这样的外部服务的区域,但是有一些骇客可以构建自己的小服务,显示网站并运行你自己的JS(认为iFrames或类似的东西)


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

解决方案

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)

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

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