tags:

views:

76

answers:

1

I know how to listen for keystrokes CTRL+F, alerting me that the user has probably asked to bring up the "find in page" search option in their browser.

Is there a way to listen for when the user has brought up the "find in page" search option using the browser menu item?

+5  A: 

That isn't part of the normal JavaScript implementation. JS lives in a sandbox, which means it is totally unaware of anything beyond the scope of the DOM except when the browser chooses to grace it with a bit of information. Opening the find dialog/bar is not one of those.

Going in that direction would start to cross the line of privacy vs invasiveness. If a web page can know what you're doing in your browser, that opens up a massive set of problems.

However, you can know if the web page has lost focus, which includes (among many, many other things of course) launching "Find". For a stupid-simple example, put this at the bottom of your page, after </body>. (You can be smarter about it by attaching the event after onload):

<script type="text/javascript">
document.onblur = handleBlur;

function handleBlur()
{
    //do something
}
</script>
Rex M