Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»JavaScript»How to Redirect User to Another Webpage with JavaScript

    How to Redirect User to Another Webpage with JavaScript

    RahulBy RahulNovember 28, 20141 Min ReadUpdated:September 12, 2019

    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
    Previous ArticleHow to check if string contains substring in JavaScript
    Next Article How to Get Query String Values using JavaScript

    Related Posts

    What is difference between var, let and const in JavaScript?

    3 Mins Read

    How to Replace String in JavaScript

    Updated:June 13, 20222 Mins Read

    JavaScript Program to Add Two Numbers

    Updated:June 9, 20222 Mins Read

    How to Install ReactJS on Ubuntu 20.04

    3 Mins Read

    Remove First Character from String in JavaScript

    1 Min Read

    10 Useful JavaScript Console Methods

    Updated:June 9, 20223 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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