Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

location.href = 'URL' redirects to a new page not a new website

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading