Browser Ctrl+F find non-visible text

2019-06-16 12:20发布

问题:

Can the browser feature of Ctrl+F to find text be integrated with text in popup windows.

I'd like to have some scientific reference information given when someone hovers over a species name in a web page. Generating the popup, tooltip style text is no problem, the problem is that anyone using Ctrl+F won't be able to find it, or if I position the text out of view when not required, it will be found but be invisible.

The same sort of effect applies to "accordion" style expanding text areas.

I'm looking for some sort of event generated when find is highlighting a result.

回答1:

Unfortunately there is no such event, you can't interfere with the built-in find.

About the best you can do in this case is to provide your own search function in-page, which searches the DOM for Text nodes containing the given text, highlights them, and opens up any closed accordions they're in.



回答2:

The only idea I have, is to put all the text from your popups in one additional scrollbox (maybe at the bottom of the page) with a height just large enough to display one set of detail information at a time. This way, it doesn't take up too much space on the page, and the text can still be found using Ctrl+F.