1

In Google Chrome, I want to trigger the browser's 'find' functionality from Javascript. I tried the following which does not work.

window.find("sometext")

How can I do this? Is this possible?

Note that simple 'DOM' search is not possible, because I have an iframe with an embedded PDF inside. The CTRL+F in chrome searches the DOM on the page and any PDF inside of it.

Developer Guy
  • 2,318
  • 6
  • 19
  • 37
Rolando
  • 58,640
  • 98
  • 266
  • 407
  • 1
    Assuming that your text is somewhere that;s displayed on a page, then probably a good way to start is to understand what the DOM is. – NoelB Apr 17 '18 at 18:41
  • 1
    Works for me... – Adjit Apr 17 '18 at 18:41
  • 1
    https://developer.mozilla.org/en-US/docs/Web/API/Window/find (note the really big red box at the top) – Kevin B Apr 17 '18 at 18:42
  • 2
    *"I want to trigger the browser's 'find' functionality from Javascript"* you mean, the thing you get with CTRL+F? try `alert('Please press CTRL+F')`. Otherwise, it can't be done. – Kevin B Apr 17 '18 at 18:43
  • That is correct. I do not want to hit CTRL+F. I want to hit a button that triggers the find box to come up, OR execute the same functionality as that passing text into it. – Rolando Apr 17 '18 at 18:53
  • @NoelB, this text could be in an iframe or a PDF inside of an iframe. – Rolando Apr 17 '18 at 18:53
  • maybe a jQuery.grep of document.body.innerHTML – Rob S. Apr 17 '18 at 19:06
  • @Rolando I see. Maybe you can use this as a starting point: https://stackoverflow.com/questions/29987478/pdf-js-using-search-function-on-embedded-pdf – NoelB Apr 17 '18 at 19:14
  • @Kevin B That is exactly what I want to do. I saw a window.find in some post, but it does not work in Chrome.. looking for something simple like that for the current version of Chrome. If it's not possible, it's not possible, but it seems like it would be very useful. – Rolando Apr 17 '18 at 21:31

0 Answers0