javascript - onkeydown works on some websites and on some it doesn't -
i trying set keyboard shortcuts gmail. use tampermonkey , onkeydown function. found out gmail special website, because found on many websites approach works, not on gmail. tried these 3 options, none work. suggest?
// @match https://mail.google.com // have line
option 1
document.onkeydown = keydown; function keydown(evt){ console.log("hhwhehehheeheh"); }
option 2
document.documentelement.onkeydown = keydown; function keydown(evt){ console.log("hhwhehehheeheh"); }
option 3
document.body.focus(); document.documentelement.onkeydown = keydown; function keydown(evt){ console.log("hhwhehehheeheh"); }
your option 1 correct, problem pattern: // @match https://mail.google.com
use follow pattern instead: // @match https://mail.google.com/*
the problem pattern fits https://mail.google.com
without path, gmail content not served https://mail.google.com
it's use location path https://mail.google.com/mail/...
have add *
pattern in order load script.
using second 1 @match
script work me:
// ==userscript== // @name new userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try take on world! // @author // @match https://mail.google.com/* // @grant none // ==/userscript== /* jshint -w097 */ 'use strict'; document.onkeydown = keydown; function keydown(evt){ console.log("hhwhehehheeheh"); }
see @match
more details
hope helps,
Comments
Post a Comment