Home > Article > Web Front-end > JavaScript web page keyword highlighting code_javascript skills
//Javascript code that highlights web page keywords
var keys = [
var bookmark;
if(document.createRange){
var range = document.createRange();
}else{
var range = document.body.createTextRange();
bookmark = range.getBookmark();
}
var key;
for(var i = 0;key = keys[i];i ){
if(range.findText){
Range.collapse(true);
range.moveToBookmark(bookmark);
while(range.findText(key[0])){
Range.pasteHTML(range.text.fontcolor(key[2]));
}
}else{
var s,n;
s = window.getSelection();
s.collapse(document.body,0);
while(window.find(key[0])){
var n = document.createElement("SPAN");
n.style.color=key[2];
s.getRangeAt(0).surroundContents(n);
}
}
}