javascript - How do I locate certain words on a webpage -


i doing small project requires me locate word , highlight word inside web browser.

to put simply, have following questions:

  1. i wondering if there location(x,y) tagged each word on webpage.

  2. could point me direction of useful tutorials working within webpage.

i implement following code , have interact webpage on google chrome. simple find , highlight function.

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);     } } 

}

thank time , effort.

i think covers want. caters considering search term phrase or individual words.

pure javascript search , text highlighting


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -