1

I am trying to make a project that involves redirecting to another website. I am having trouble doing that.

Here is my code

document.getElementById("ContinueToWeb").onclick = function () {
   location.href = "google.com";
}
<html>
  <head>
    <!--Some code here-->
  </head>
  <body>
    <!--Some code here-->
    <button id="ContinueToWeb">Continue</button>
  </body>
</html>

For some reason, it redirects from c:/folder/index.html to c:/folder/google.com even though I am telling it to go from c:/folder/index.html to google.com. Do you know what's happening?

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
Jerry Lin
  • 115
  • 1
  • 9

1 Answers1

2

You have to add the protocol for the link or else it defaults to what the site is using which is your local filesystem. Use https://www.google.com instead

gbac
  • 235
  • 3
  • 12