user12905671
user12905671

Reputation:

Is it possible to reload the page on key press in javascript (without focusing the page)?

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

Answers (2)

Kanishk Shrivastava
Kanishk Shrivastava

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

user12889738
user12889738

Reputation:

It's not possible in javascript, What you used is good(don't need to improve)

Upvotes: 1

Related Questions