开发者

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 Mozi开发者_如何学JAVAlla'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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜