【发布时间】:2013-08-18 09:13:59
【问题描述】:
我正在做一个小项目,需要我找到某个单词并在网络浏览器中突出显示该单词。
简单来说,我有以下几个问题:
我想知道网页上的每个单词是否都有一个 location(x,y) 标记。
谁能告诉我一些关于在网页中工作的有用教程的方向。
我想实现以下代码并让它与谷歌浏览器上的任何网页进行交互。这是一个简单的查找和突出显示功能。
function doSearch(text) {
if (window.find && window.getSelection) {
document.designMode = "on";
var sel = window.getSelection();
sel.collapse(document.body, 0);
while (window.find(text)) {
document.getElementById("button").blur();
document.execCommand("HiliteColor", false, "lavender");
sel.collapseToEnd();
}
document.designMode = "off";
} else if (document.body.createTextRange) {
var textRange = document.body.createTextRange();
while (textRange.findText(text)) {
textRange.execCommand("BackColor", false, "lavender");
textRange.collapse(false);
}
}
}
感谢您的时间和精力。
【问题讨论】:
标签: javascript webpage highlighting