Reputation:
I want to reload my page on key press in JavaScript. I already use this code,
document.addEventListener('keyup', function (e) {
if (e.keyCode == 13)
window.location.reload();
});
from this post-Refresh page on ENTER / RETURN key press
But the problem is when the current page is not in focus it does not work. For example when I open the developer tools or click on it. Then the keypress event is not working for focus out (I think so).
Is it possible to do it without focusing on the page using JavaScript?
Upvotes: 0
Views: 512
Reputation: 131
It's not possible to do in that way in JavaScript, But, why and in which case you need to reload the page? I mean when you not focused on page.
Upvotes: 0
Reputation:
It's not possible in javascript, What you used is good(don't need to improve)
Upvotes: 1