For example if I have a web page HTML like below
<body>
Hello Techies, <br>
Techies here.
</body>
If I search for "Techies" using
var sel = window.getSelection();
sel.collapse(document.body, 0);
document.body.offsetHeight;
if (window.find("Techies", true)) {
document.execCommand("hiliteColor", false, "YellowGreen");
sel.collapseToEnd();
}
It is Highlighting only the first occurred of the "Techies". But when I search with Ctrl+F the first occurrence will be highlighted in Dark and next occurrences will be highlighted in light color mode. How can I achieve the same with the above code.
Try using a while
loop:
if (window.find("Techies", true)) {
document.execCommand("hiliteColor", false, "FirstColor");
while (window.find("Techies", true)) {
document.execCommand("hiliteColor", false, "SecondColor");
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With