0

Is there an event that fires every time the user uses the browser search to look for a term in the page? How can I detect it and do something when that happens?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Lea Verou
  • 23,618
  • 9
  • 46
  • 48
  • 2
    Possible duplicate of:http://stackoverflow.com/questions/1793864/listen-for-events-from-browser-find-window-in-javascript – SomeKittens Jul 04 '12 at 18:05

1 Answers1

0

I have used the following for CTRL+F event, look at: http://www.sencha.com/forum/showthread.php?68120-Handle-Ctrl-F-event-in-IE-Safari-and-Google-Chrome

  Ext.EventManager.on(document, Ext.isOpera ? 'keypress' : 'keydown', function(e){
      if(e.keyCode == 70 && e.ctrlKey){
        e.stopEvent();
        if(Ext.isIE){
        e.browserEvent.keyCode = 0;
       }
    // do stuff
       }
    return false;
    });
ama2
  • 2,611
  • 3
  • 20
  • 28
  • What if a user uses the quick search (just start typing)? Firefox has that feature, I don't know for other browsers. – Nikola K. Jul 04 '12 at 18:17
  • Besides what Nikola said, there are plenty other issues with this approach: 1. Ctrl+F isn't always the shortcut. On Mac, it’s Cmd+F 2. It won’t catch subsequent searches, where it’s just hitting Enter 3. It won’t catch searches triggered via the mouse (through the browser menu) – Lea Verou Jul 05 '12 at 16:09