![](/img/trans.png)
[英]overriding the browser's CTRL+F and replace it with Silverlight custom search
[英]How does Google Drive (or other services) capture the Ctrl+F or Command+F input for a custom search box?
是否可以創建自定義“查找”框,類似於按Command + F或Ctrl + F時Google雲端硬盤執行的操作? 我是一個完整的菜鳥,我不確定如何更好地表達這個問題,對不起!
他們捕獲document
上的keydown
事件並阻止發生默認操作,而是自己做:
document.addEventListener("keydown", function(e) {
if (e.ctrlKey && (e.which || e.keyCode) == 70) {
e.preventDefault();
alert("Search!");
}
}, false);
現場示例:
document.addEventListener("keydown", function(e) { if (e.ctrlKey && (e.which || e.keyCode) == 70) { e.preventDefault(); alert("Search!"); } }, false);
<p>Click here to focus the snippet's document, then press Ctrl+F</p>
處理程序收到的事件對象具有ctrlKey
屬性,如果按下ctrl鍵,則該屬性將具有真實值。 在大多數的瀏覽器,它也將有which
屬性,說哪個鍵,但在一些它的keyCode
,所以在上面我用好奇強大||
操作員使用瀏覽器提供的任何一種。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.