Hello everyone. Does anyone know if it is possible to redirect a browser with Javascript? If it is, could someone please give me a clue as to how it is done? I have searched the w3schools tutorial where I started learning Javascript but can't find anything on this. Any help would be appriciated. Thanks.

Steven.

A Google for "javascript redirect" would have answered yor question much quicker than posting here.

window.location="http://www.yourdomain.com/";

There is also the window.replace() method, which takes a string inside the parantheses. The difference between the .replace() method and the .location property, is that .replace() doesn't store the new page in the browser history.

This code is used specifically to redirect one Web page to another (i.e. if your Web site has moved, put this code at the old location)

<html>
  <head>
    <title>Redirect JavaScript-browsers</title>

    <script language="JavaScript">
      <!-- Beginning of JavaScript --------
        this.location = "http://www.newsite.com";
      // -- End of JavaScript code -------------- -->
    </script>

  </head>

  <body>
    This site is now located at <a href="http://www.newsite.com">http://www.newsite.com</a>.
  </body>
</html>

I hope that helps you out.

commented: Very helpfull. +1

Thanks guys.

Steven.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.