How To Use Redirect Using JavaScript?


Share:
Published By: Admin, Published On: Nov 18, 2021, Category: Javascript


Hello Friends,

Now let's see example of how to use redirect example.We will check how to use redirect. This is a short guide on use redirect in javascript. Here you will learn how to use javascript redirect. Let's get started with how to use redirect in javascript.

Here i will give you many example how to use redirect using javascript.

Example : 1
<html>
    <head>
        <title>How To Use Redirect Using JavaScript? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Use Redirect Using JavaScript? - MyWebtuts.com</h3>
        <p>Click following button to see the effect.</p>

        <form>
            <input type = "button" value = "Redirect" onclick = "pageRedirect()" />
        </form>
        <script type = "text/javascript">
            function pageRedirect(){
                window.location = "https://www.mywebtuts.com/";
            }
        </script>
    </body>
</html>
Output : Example : 2
<!DOCTYPE html>
<html>
    <head>
        <title>How To Use Redirect Using JavaScript? - MyWebtuts.com</title>
    </head>
    <body>
        <h3>How To Use Redirect Using JavaScript? - MyWebtuts.com</h3>
        <p>Using replace() the currct document will replace with new one.</p>
        <button onclick = "pageRedirect()">Replace</button>

        <script>
            function pageRedirect() {
                location.replace("https://www.mywebtuts.com")
            }
        </script>
    </body>
</html>
Output :

It will help you...

Share: