I have a page with a few <div>
containers.
How to give focus to one of them on page load, so that the user can use arrow keys to scroll (or even SPACE to scroll) without having to click on the div
first?
I have tried:
<div id="main" autofocus>
but autofocus
doesn't seem to work on non-input div
.
_
This could be a solution but then the browser address bar would display the id http://example.com/#main which I don't want:
<body onload="location.hash = 'main';">
<div id="main">content</div>
</body>
_
Example: when you open https://en.wikipedia.org/wiki/Main_Page, you can immediately use Down arrow key or Space to scroll, without having to click anywhere.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…