Reputation: 53
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?
Upvotes: 3
Views: 4985
Reputation: 11
Here you'll find a helpful key code generator and reference: http://www.javascriptkeycode.com
Upvotes: 0
Reputation: 442
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
}
Upvotes: 2
Reputation: 37701
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();
})
Upvotes: 4