A tutorial to implement page redirection function with JavaScript

Source: Internet
Author: User
Tags time interval

This article mainly introduces the use of JavaScript to achieve page redirection function of the tutorial, is the basic knowledge of JS learning, the need for friends can refer to the

What is page redirection?

When you click on a URL to access a page x, but inside you are directed to another page y, just because of page redirection. The idea is to refresh from a different JavaScript page.

There may be various reasons why you want to redirect from the original page. Several reasons are listed below:

If you don't like your domain name, you can redirect to a new one. Also, to guide all visitors to the new site. In this case, you can keep the old domain name, but put it on a page to a page redirect so that all the old domain visitors can come to the new domain name.

Based on the browser version, or the name of a different page, can also be based on different countries, rather than server-side page redirection, you can use the client page redirect to the landing user on the corresponding page.

Search engines may have included new pages. However, in moving to another domain name, then do not like to lose visitors through the search engine. Therefore, you can use the redirection of the client page. But keep in mind that this should not be done to make the search engine a fool, otherwise, this may allow the site to be banned.

How does the page re-orientation work?

Example 1:

This use of JavaScript in the client page redirection is very simple. Site visitors redirect to a new page, just add a line to the head section as follows:

?

1 2 3 4 5 6 7

Example 2:

You can redirect it to a new page before displaying the appropriate information to the site visitors. This will require a bit time delay to load the new page. The following are simple examples to achieve the same:

?

1 2 3 4 5 6 7 8 9 10 11 12-13

The settimeout () here is a built-in JavaScript function that can be used to execute another function after a given time interval.

Example 3:

Here is an example of redirecting a Web visitor based on its browser:

?

1 2 3 4 5 6 7 8 9
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.