I found that many websites provide the shortkey '/' as a way to focus the search box like YouTube, Zhihu, etc. However, I found that it doesn't work on Stack Overflow. This feature is written in front-end JavaScript. Can we add this feature in our website?
<body>
<input type="text">
<script>
var search = document.querySelector('input');
document.addEventListener('keyup', function(e) {
// console.log(e.keyCode);
if (e.keyCode === 191) {
search.focus();
}
})
</script>
</body>
When I press '/' in my keyboard, I can jump to search box and input.
s
key activates the search bar. You can see all keyboard shortcuts by pressing?
?
(requires Shift on some keyboards). The zoom level must sufficiently low to see all of them.