Close Menu
    Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Programming»JavaScript»How to Redirect User to Another Webpage with JavaScript

    How to Redirect User to Another Webpage with JavaScript

    By RahulSeptember 12, 20191 Min Read

    This tutorial will help you to redirect a webpage to another webpage using JavaScript. Here are 3 examples of redirecting webpage to another with JavaScript.

    Example 1:

    We can redirect user to other page using window.location.replace in JavaScript. window.location.replace has pretty similar to an HTTP redirect.

    1
    window.location.replace("https://example.com");

    Example 2:

    It is better to use window.location.href in place of window.location.replace, because replace() function does not put the originating page in the session history.

    1
    window.location.href = "https://example.com";

    Example 3:

    We can also simply redirect to any internal website page using window.location.

    1
    window.location.href = "/other-page/";

    javascript redirect url website
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Diverse Ways to Instantiate Objects in JavaScript

    JavaScript Code to Detect Web Browser

    JavaScript Code to Detect OS (Operating System)

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Change Port in Next.Js
    • Ubuntu 24.04 LTS: The Future of Open-Source Excellence
    • How to Execute Linux Commands in Python
    • Creating MySQL User with GRANT OPTION
    • Where to find crontab (cron) logs in Ubuntu & Debian
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.