How to implement automatic website page Jump: PHP, JSP (bottom) _ javascript skills

Source: Internet
Author: User
In many cases, we need web pages to have the automatic jump function. For example, if a user in a forum successfully logs on, posts, replies, or sends a message or replies to a message book, if the user does not have any mouse clicks, after a certain period of time, the page automatically jumps to the preset page. This article discusses several implementation methods for Automatic Webpage redirect.
Method 1: Using meta tag is an indispensable tag in html. It provides the metadata of the document. Its parameters mainly include:
① Http-equiv: the header of the HTTP file related to the data in the document
② Content: data related to naming HTTP headers
③ Name: Document Description
④ Url: the URL associated with the metadata. When we define the attribute http-equiv as refresh, the system will jump to the corresponding page within a certain period of time according to the value specified by content when opening this web page, content = "seconds; url = url" means that you have defined too many times to jump to the specified url. The following meta tag tells the system that the page automatically jumps to the dark horse online power after one second:

The above code needs to be added to the HTTP document header,AndIn general, meta Tags keep upLater. If you need multiple meta tags, each of them can take up one row.
This method is applicable to any environment and contains static website space.
Method 2: the header function is one of the HTTP-related functions in php built-in functions. This function sends the HTTP header to the browser. You can use it to redirect the URL, that is, to redirect the page to another specified webpage. In the following example, the homepage is automatically displayed:
Header ("Location: http://www.jb51.net /");
You must note that the header function can only be used in the page code.Before the tag, that is, the HTTP header does not have any other header () Before it is sent to the browser, and the previous page cannot print or echo any content. In other wordsBefore it appears, the program simply processes the header event. Despite such strict requirements, you can use it flexibly to achieve the automatic page Jump function. For example, you can log on to the page and determine where the page jumps by judging whether the data submitted by the user is legal. The following is a simple example:

The Code is as follows:


/* Login program-File Name: login. php
Program function-determine the user logon password */
If ($ _ POST ['submit ']) {
Session_start ();
If ($ _ POST ['pws '] = '000000') {// if the password is 123
$ _ SESSION ['passwd'] = '000000'; // write SESSION data
Header ("Location: index. php"); // jump to the normal page
} Else {
Header ("Location: login. php"); // jump to the logon page
}
}
// The form code is omitted (you can also use pure html code to write a form. If so, the code should be placed after the program
?>
/* Check session data-file name: index. php
Program function-checks whether the password in the session data is 123. If not, the system returns
Logon page */
Session_start ();
If ($ _ SESSION ['passwd']! = '20140901') header ("Location: login. php ");
// Other code (the pure HTML code should be written after the program)
?>


This method can only be used in a space environment that supports php.
Method 3: JavaScriptJS is very flexible and can be used to create powerful program scripts. Here is only a simple JS example of automatic page Jump. After the following code is executed, the browser will automatically go to The website. This code can be placed in any valid location on the page:
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.