jquery監聽ctrl + c 和 鼠標右鍵“復制”事件


<script type="text/javascript" src="jquery.min.js"></script>  
    <script type="text/javascript">  
  
        //  監聽 ctrl + c事件  
        $(document).unbind('keydown').bind('keydown', function(e){   
            if(e.ctrlKey && e.keyCode  == 67) {   
                doSomething();  
                // 返回false, 防止重復觸發copy事件  
                return false;  
            }  
        })  
          
        // 鼠標右鍵的復制事件  
        $(document).unbind('copy').bind('copy', function(e) {  
            setTime();  
            console.log('右鍵復制 監聽成功');  
        });  
  
        function doSomething(){  
            setTime();  
            console.log('ctrl + c 監聽成功');  
        }  
   
        function setTime(){  
            if(window.localStorage) {  
                let time = localStorage.getItem('time');  
                time ? time ++ : time = 1;  
                localStorage.setItem('time', time);  
            }  
        }  
  
    </script>  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM