Menu ▼



Posted By :
avatarmrkraju
Total Views : 783

Redirect web page to another page using javascript

In this example we will see how to redirect one web page to another web page using javascript. we need to set the redirect url to window.location.href, then the web page will be redirect to given url.

Syntax: window.location.href = "url here";

Example

Redirect this web site to

  • If we give the relative path as url, then the page will be redirected to another page with in the web site.
    • ex : if we give the url as "/blogs/" then the page will be redirect to "http://www.dotnetlearners.com/blogs/"
  • we can give the another website url, so that it will redirect to another web site.
    • ex: http://www.google.com

Source Code

<html>
<head>
    <title></title>
    <script language="javascript">
        function redirectwebsite() {
            var url = document.getElementById("txtwebsiteurl").value;
            window.location.href = url;
        }
    </script>
</head>
<body>
    Redirect this web site to
    <input type="text" id="txtwebsiteurl" value="http://www.dotnetlearners.com" style="width: 410px;" />
    <input type="button" value="Redirect" onclick="redirectwebsite();" />
</body>
</html>





comments powered by Disqus


Search dotnetlearners.com