user902998
user902998

Reputation:

How to fire an event when a Search through ctrl+f happened in a webpage

I am writing a script for Mozilla to done following requirement.When user click ctrl+f and search some text in a web page through,
If it is found that should be added with yellow background. I am strucked in start to write this script. Please someone help me with the idea. I am writing it through "greasemonkey".
If a user search through Mozilla's native findbar. If it is found that should be highlighted with some color. Even if another search happens old highlight should not be removed.
Please someone help me.

Upvotes: 1

Views: 876

Answers (1)

Maxx
Maxx

Reputation: 4072

This will work...

ctrlPressed = false;

$(document).keydown(function(e){

   if(e.keyCode == 17){                           //17 is "ctrl"
         ctrlPressed = true;
   }

   if(ctrlPressed && e.keyCode == 70){            //70 is "f"
       alert("Page is being searched");
   }

});


$(document).keyup(function(e){

   if(e.keyCode == 17){ 
         ctrlPressed = false;
   }

});

...but I suspect there may be a more straightforward way.

Upvotes: 1

Related Questions