javascript - Check if selected text on page has some word in it -


with below code can find text on page , highlight

document.designmode = "on"; if(window.find(textline, true)){          document.execcommand("backcolor", false, "rgb(250, 250, 0)");    textselection.collapsetoend(); } document.designmode = "off"; 

but requirement find text in selected text. i.e want highlight text if word existing in selected text. surroundcountents() method can wrap initial text div element , try searching html, looking solution code above. suggestions please?

it's not supported use window.find find text selected previous window.find window.find method (from see) not support searching in ranges or selections.

api here: http://help.dottoro.com/ljkjvqqo.php

i suspect use window.find again keyword , check caret position, etc verify result in original result seems inefficient on first glace. have @ selection api , ranges... https://developer.mozilla.org/en/docs/dom/selection run 2 window.find , compare ranges see second 1 within first one.

i think plain simple javascript text search quite efficient , fast want.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -