2014-09-02 13 views
1

userscript에서 keydown 이벤트를 캡처하고 웹 사이트 자체에서 이벤트를 숨길 필요가 있습니다. 나는. 웹 사이트는 keypress를 감지 할 수 없어야합니다. 내가 함께 테스트입니다 https://www.robertnitsch.de/test/userscript에서 keydown 이벤트 캡처 및 웹 사이트에서 숨기기

: 내 테스트 웹 사이트에서 확인 할 수

// ==UserScript== 
// @name  test 
// @namespace www.robertnitsch.de 
// @description test 
// @include  https://www.robertnitsch.de/test/ 
// @version  1 
// @grant  none 
// ==/UserScript== 

document.addEventListener("keydown", function(evt) { 
    console.log("userscript", evt); 
    evt.stopPropagation(); 
    return false; 
}, true); 

그러나, 페이지가 여전히를 keyDown 이벤트를 감지 할 수 있습니다 :

는 내가 Greasemonkey와 userscript에 다음 코드를 시도 a, s, d 등 간단한 키

+0

Jquery allowed ?? –

+0

예, jQuery를 사용할 수 있습니다. – robert

답변

2
// ==UserScript== 
// @name   test 
// @namespace http://stackoverflow.com 
// @version  1.0 
// @description http://stackoverflow.com/questions/25631170/capture-keydown-event-in-userscript-and-hide-it-from-the-website 
// @include  https://www.robertnitsch.de/test/ 
// @author  zanetu 
// @grant  none 
// @run-at  document-start 
// ==/UserScript== 

document.addEventListener('keydown', function(event) { 
    event.stopImmediatePropagation(); 
}, true); 
+0

신난다, 작동한다! 나는'@ run-at'과'stopImmediatePropagation()'에 대해 몰랐다. :-) – robert

0
<!DOCTYPE html> 
<html> 
<head> 
    <script src="jquery.js"></script> 
    <script type="text/javascript"> 

$(document).ready(function(){ 
$('*').off('keyup keydown keypress'); 
}); 
    </script> 
</head> 

<body> 
test 
</body> 
</html> 

위의 코드가 작동합니다!

확인하고 확인하십시오!

+1

죄송합니다. 그러나 이것은 제가 후일이 아닙니다. 실제 웹 사이트의 소스 코드를 변경할 수 없습니다. – robert

+0

당신은 excatly 싶어? –