Javascript redirect function is not redirecting

function myFunction() {
  location.replace("https://www.w3schools.com")
}

in the script tag

  <button onclick='myFunction()'>Submit</button>

in the html

Any idea why this very basic command doesn’t work?