Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// "/"で検索窓にフォーカスする
(() => {
const onKeyDown = function(e) {
if (e.keyCode == 191) { // 191 == "/"
if (location.pathname == "/YOUR_PROJECT/" || location.pathname == "/YOUR_PROJECT/search/page") {
if (document.activeElement != $(".form-control")[0]) {
e.preventDefault();
$(".form-control")[0].focus();
}
}
}
}
document.addEventListener('keydown', onKeyDown);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment