Home > Blockchain >  Javascript redirect function is not redirecting
Javascript redirect function is not redirecting

Time:04-16

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?

CodePudding user response:

check this example: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_redirect_webpage

If your button is inside the form then need to specify as type of button

<form>
 <button onclick="myFunction()" type="button">Replace document</button>
</form

CodePudding user response:

I tested your code and it works fine.. Try clearing your cache inspect and right click on reload choose clear cache.

Did u link your script file ?

<script src="script.js"></script>
  • Related