Is there a way to detect find on the page searches in javascript

前端 未结 4 569
栀梦
栀梦 2020-11-30 12:26

each browser has find on page functionality (ctrl+F). Is there a way to detect user searches in javascript so that I could attach additional actions.

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 13:07

    As initially suggested by @Nicola Peluchetti, here is a slightly improved version by feature sniffing:

    window.onkeydown = function(e){
        var ck = e.keyCode ? e.keyCode : e.which;
        if(e.ctrlKey && ck == 70){
            alert('Searching...');
        }
    }
    

    Browser search test case »

提交回复
热议问题