[英]How can I bookmark a specific row of an HTML page? (should work in chrome and if possible IE)
I'm reading stuff online from a site that prints out to HTML ebooks. 我正在从一个打印到HTML电子书的网站上在线阅读内容。
I don't want to download anything or convert anything, but i want to bookmark the current row i'm at in such a way that when i click the bookmark, i want to be taken to the respective row (not just the page). 我不想下载任何东西或转换任何东西,但我想以这样的方式为我当前的行添加书签,当我点击书签时,我想要被带到相应的行(不仅仅是页面) 。
The site contains just text, so i can't do the trick with the "#" like www.wikipedia.org/article#subchapter 该网站只包含文字,所以我无法像www.wikipedia.org/article#subchapter那样使用“#”。
(my apologies for the noobish language, i'm a junior dev, worked in Java and ABAP, but no experience in web related stuff) (我为noobish语言道歉,我是一名初级开发人员,曾在Java和ABAP工作,但没有网络相关的经验)
I imagine i could save bookmarks that are actually Javascript code, that take me to the speciffic line, but wouldn't know where to begin, not being a web guy. 我想我可以保存书签,这些书签实际上是Javascript代码,它带我去了特定的行,但不知道从哪里开始,不是一个网络人。
Any ideas (or implementations) would be awesome. 任何想法(或实现)都会很棒。
Thx, you guys rule. 谢谢你,你们统治。
[EDIT] Could also work AFAIK if my bookmark saved a part of the text, and then i'd get taken to that text when clicking the bookmark [编辑]如果我的书签保存了文本的一部分,也可以使用AFAIK,然后点击书签时我会被带到该文本
[EDIT] [编辑]
http://gutenberg.spiegel.de/buch/2095/2 This is basically the site. http://gutenberg.spiegel.de/buch/2095/2这基本上就是网站。 don't mind the german.
不介意德国人。
There is no such thing as a line in the DOM. DOM中没有这样的东西。 But you can scroll to a element.
但是你可以滚动到一个元素。 There is a really nice jQuery extension that does it scrollTo .
有一个非常好的jQuery扩展,它使scrollTo 。
But to make a bookmark could be a bit messy. 但制作书签可能有点乱。 Because you need both jQuery and this plugin.
因为你需要jQuery和这个插件。
To make it work you would have to book mark with: 为了使它工作,你必须预订标记:
javascript: document.location = [website url] ; [jQuery's File content] ; [the plugin] ; [jQuery scrollTo code]
Where [jQuery scrollTo code]
would be something like: 哪里
[jQuery scrollTo code]
会是这样的:
$(...).scrollTo( $('ul').get(2).childNodes[20], 800 );
You could write a little chrome extension that inserts a tag every 100 words. 您可以编写一个小的chrome扩展,每100个字插入一个标记。 Then you could in fact use the # syntax you referenced.
那么你实际上可以使用你引用的#语法。
Inserted into HTML**: 插入HTML **:
<a name="line40" />
Your bookmark 你的书签
<a href="page.html#line40">bookmark</a>
**Note: with HTML5 use a tag with "ID" instead of anchors with "name" attribute. **注意:HTML5使用带有“ID”的标签,而不是带有“name”属性的锚。
BlackJackMack beat me to it for the general idea, but here is some code to insert elements as well as a way to jump to particular hash after the fact (needed since when you first get to the page the ids won't be there). BlackJackMack以一般的想法打败了我,但是这里有一些插入元素的代码以及一种在事实之后跳转到特定哈希的方法(从你第一次到达页面时就需要ids不在那里)。
paragraphs = document.getElementsByTagName('p');
for (x = 0; x < paragraphs.length; x++) {
var p = paragraphs[x];
var a = document.createElement('a');
a.id = 'p' + x;
a.href = '#' + a.id;
a.innerText = '#';
p.parentNode.insertBefore(a, p)
}
if (document.location.hash) {
var hash = document.location.hash;
document.location.hash = '';
document.location.hash = hash;
}
I only tested this on Chrome, so keep that in mind. 我只在Chrome上测试了这一点,所以请记住这一点。 Can just paste it into the console to try it out.
可以将其粘贴到控制台中进行试用。 I didn't use jQuery or any plugins to make it easier to adapt into bookmark code.
我没有使用jQuery或任何插件来更容易适应书签代码。
Keep in mind this will only work if the page correctly uses paragraph tags, so it'll have to be adapted if everything is divs or something. 请记住,这仅在页面正确使用段落标记时才有效,因此如果所有内容都是div或其他内容,则必须进行调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.