UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Redirect url in javascript

Demo and Code for how to redirect url in javascript

by Athil


Posted on 15 Jun 2017 Category: Javascript Views: 530

Edited on 10 Jun 2018


DEMO

Hi Here I am going to show how to redirect URL using javascript

Syntax

window.location = url;

Example 

window.location = "https://www.google.com";

Full Demo Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Demo for Javascript redirect</title>
</head>
<body>
<h1>Demo for Javascript redirect </h1>

    <button onclick ="redirect();" >  Redirect to google  </button>

    <script>
        function redirect()
        {
            window.location='http://www.google.com';
        }
        </script></body></html>

 



Leave a Comment:


Advertisement