机器人的WebView:突出使用JavaScript的网页的特定词? [英] Android webview: highlight a specific word in a page using javascript?

查看:117
本文介绍了机器人的WebView:突出使用JavaScript的网页的特定词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用在我的Andr​​oid应用程序中的web视图。我想知道是否有可能突出或使用在javascript code做?强调一个特定的单词/句子/段落加载的页面

i am using a webview inside my android application. I would like to know if it is possible to highlight or underline a specific word/sentence/paragraph in a loaded page using code done in javascript?

感谢

推荐答案

您应该看看此页。做一个视图源。

You should look at this page. Do a view source.

他们用纯Javascript的 - 即使不是jQuery的 - 突出网页上的特定词。

They use pure Javascript--not even jQuery--to highlight particular words on the webpage.

他们基本上加载所有他们想通过搜索到一个变量中,不断找到他们想要突出的indexOf 搜索词的文字。当他们发现这个词的索引,他们建立一个新的字符串与索引之前的一切+ A <跨度类=高亮> +搜索词+ < / SPAN> 。然后,他们继续搜索。一旦他们已经搜索并重建所有的文字替换它们与新的文本DOM中的旧文本。

Basically they load all of the text they want to search through into a variable and continuously find the indexOf the search term they want to highlight. When they find the index of the term, they build a new string with everything before that index + a <span class="highlighted"> + the search term + </span>. Then they continue searching. Once they've searched and rebuilt all the text they replace the old text in the DOM with the new text.

他们也有沿 .highlighted {background-color的线条一些CSS:黄色; }

这篇关于机器人的WebView:突出使用JavaScript的网页的特定词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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