Search code examples
javascripthtmlcssaddeventlistener

Javascript-reloading the page using AddEventlistener


I want to use AddEventListener in javascript to reload the page when i press Enter(Like what F5 automatically do), and overall I want to know how to manipulate the shortcuts that being already defined in the computer(Like F5) using JavaScript. thanks for help

I tried to use Addeventlistener but i couldn't specify it to reload the page


Solution

  • Try this:

    document.addEventListener("keyup", (event) => {
     if (event.key === 'Enter') {
          location.reload(true)
        }
    });