Listen for Events from Browser “Find” Window in Ja

2020-02-15 02:52发布

Is there a way to listen for typing into the browser's "find" window in JavaScript?

this window

I'd like to be able to reinterpret the search text from JavaScript. What do I need to add an event listener for?

3条回答
Viruses.
2楼-- · 2020-02-15 03:32

Hardly. Even if it were possible through some loophole to listen to the browser's built-in "find" function, it would be a privacy issue and get closed sooner or later. I'm quite sure you won't be able to listen to the keystrokes either, as they take place outside the page's focus.

查看更多
我命由我不由天
3楼-- · 2020-02-15 03:40

No. There is no web standard that defines a "find" dialog, let alone events for it. The find dialog is vendor-specific and for all you know, browser X's "find" dialog lets users enter a mathematical function and match/"find" pixels on the page with it.

查看更多
你好瞎i
4楼-- · 2020-02-15 03:56

I don't know of any way you can listen for a find-like event and if that's supported in any browser it sure isn't a portable solution.

I also don't know what you're trying to achieve but I think that your best option is to listen for the keyboard events that trigger the find window and attempt to cancel them while attempting to emulate the find-toolbar/window with JavaScript of your own. This is however a herculean (and nearly impossible) task due to some browsers customization of keyboard shortcuts depending on the localization (for instance, in IE, en-US uses Ctrl+F (for Find) while pt-PT uses Ctrl+L (for Localizar, meaning find)).

Conclusion: I think you're out of luck there...

查看更多
登录 后发表回答