Page navigation (Redirect) in JavaScript

What is redirecting the page?

You may have a situation when you click on a URL to go to page X but you are directed to page Y. It happens because Page Redirection - Redirects the page . This concept is different from: JavaScript - Refresh page .

There are many different reasons why you want to redirect users from the original page. Here are some reasons:

You don't like your domain name and you're trying to switch to a new domain. In this case, you may want to direct all your visitors to the new site. Here, you can maintain the old domain name, but put a single page with a redirected page so that all old domain visitors can reach the new domain.

You have built different pages based on the browser or its name or can be based on different countries, then, instead of using re-page navigation in Server-Side, you can use redirecting the Client-Side page to redirect users to the appropriate page.

Search Engines may have indexed your pages. But while moving to a new domain, you don't want to lose visitors through search engines. So you can use the redirection of the Client-Side page. But keep in mind that this should not be done to deceive Search Engine, it could make your site a banned page.

How does Page Redirection work?

The process of Page Redirection is as follows:

Example 1

It is quite simple to implement Page Redirection using JavaScript at Client-Side. To navigate visitors to a new page, you just need to add a line of code in the head area as follows:

  type = "text/javascript" >  
 Click the following button, you will be redirected to home page.  type = "button" value = "Redirect Me" onclick = " Redirect (); " /> 

Example 2

You can display an appropriate message for visitors before navigating them to a new page. This may take a little delay to load the new page. The following example shows how to do the same. Here, setTimeout () is an available function in JavaScript that can be used to execute other commands after a given time period.

  type = "text/javascript" >  

Result

Action as above to see results

Example 3

The following example shows how to navigate your visitors to another page based on the browser they use.

  type = "text/javascript" >  

According to Tutorialspoint

Last post: Event (Event) in JavaScript

Next article: Dialogs - Alert, Prompt, Confirmation in JavaScript

5 ★ | 1 Vote

May be interested

  • JavaScript in HTMLJavaScript in HTML
    in html, javascript makes the page more flexible and interactive.
  • Udemy's top 5 JavaScript coursesUdemy's top 5 JavaScript courses
    a programming language that runs on any computer in the world. a language does not need any special software to run. a language ranked among the top in the world.
  • Top site with many good JavaScript exercises to practiceTop site with many good JavaScript exercises to practice
    many people, after taking javascript courses and being equipped with some knowledge of the language they pursue, are eager to improve and cultivate these learned skills. so this article will give you a list of the top 3 websites to actually make javascript.
  • What is JavaScript?What is JavaScript?
    javascript is a programming language of html and web. it is lightweight and most commonly used as part of web pages, but their implementation allows client-side scripts to interact with users and create dynamic websites. it is an interpreted programming language with object-oriented capabilities.
  • ! = and! == What is the difference in JavaScript?! = and! == What is the difference in JavaScript?
    javascript includes operators like in other languages. an operator performs some operations on one or more operands (data values) and produces a result. today's article will help readers learn about 2! = and! == operators in javascript.
  • How to redirect pages on Google DocsHow to redirect pages on Google Docs
    on google docs also has the option of redirecting vertical or horizontal pages.
  • How to activate the new navigation bar on Android PHow to activate the new navigation bar on Android P
    now those who have upgraded their device to android p beta will be able to experience this new feature. however, in the default interface the navigation keys are still designed and if you want to activate the new navigation bar you need to make some small customizations.
  • Learn about ES6 in JavascriptLearn about ES6 in Javascript
    es6 refers to version 6 of the ecma script programming language. ecma script is the standard name for javascript and version 6 is the next version after version 5, released in 2011.
  • Navigation Bar - Navigation Bar in CSSNavigation Bar - Navigation Bar in CSS
    navigation bar - navigation bar, or menu bar, is used to navigate the main sections of a website
  • How to hide the navigation bar on Samsung Galaxy S8How to hide the navigation bar on Samsung Galaxy S8
    if the user wants to expand the content display space, it can hide the navigation bar on samsung galaxy s8.