[ Refresh page on ENTER / RETURN key press ]
I made a little quiz with HTML, CSS and JavaScript that helps me learn stuff for school. I only use it locally for myself. I'd like to make it possible to refresh the page with the ENTER key as an addition to F5 in order to make learning quicker. What's the easiest, simplest way that works locally without any additional software other than web browser?
Answer 1
You can put a listener on the document and it will intercept all keypresses, just make sure you're reloading the page when Enter is pressed:
document.addEventListener('keyup', function(e){
if(e.keyCode == 13)
window.location.reload();
})
Answer 2
Either make your quiz a form submitted on 'enter' (as @miqdadamirali suggested), or attach an 'onkeypress' event to document body and use a little bit of javascript as a handler:
function handler(evt){
if(evt.keyCode == 13) // enter key
location.reload() // refresh page
}
Answer 3
Here you'll find a helpful key code generator and reference: http://www.javascriptkeycode.com