[英]Is there a way for a website to detect keypresses?
我想知道是否無論如何網頁可以等待某些按鍵然后顯示信息,例如我輸入了一些關於我的內容,網頁重定向到關於我的頁面(但是他們輸入的文本不可見)。 當我了解到您可以通過在 google chrome 中輸入thisisunsafe進入不安全的網站並想知道該功能是否可以在網站中實現時,我獲得了靈感。
使用e.code
,其中e
是 function 中定義的事件偵聽器,而.code
是被觸發的keys code
...請參閱下面的示例,取自 MDN 文檔...
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event
const log = document.getElementById('log'); document.addEventListener('keypress', logKey); function logKey(e) { log.textContent+= `${e.code}` + ' - '; }
Get the key being pressed in your browser <div id="log"></div>
在 javascript 中,您可以使用EventListener
並且您對 go 很好
window.addEventListener("keypress", function(){
*do what you want to do here*
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.