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:
i wondering if there location(x,y) tagged each word on webpage.
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.
Comments
Post a Comment