How to Implement Automatic Webpage redirect: PHP, JSP (bottom)

Source: Internet
Author: User

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:
<Meta http-equiv = "refresh" content = "1; url = http://www.jb51.net/">
The above code must be added to the HTTP Document Header between 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 before the Copy codeThe Code is as follows:
<? Php
/* 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
?>
<? Php
/* 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:
<Script language = "javascript" type = "text/javascript"> window. location. href ("http://www.jb51.net"); </script> This Code applies to any Web environment. If you add a timer, it will be even more amazing.

Frequent page Jump problems, such as when some websites need to log out, a prompt page appears
What are you quitting a class-class phone call? Some have to make a countdown.
Method 1:
<Meta http-equiv = "refresh" content = "'Wait time'; URL = 'jump page'">
Method 2:
This is a js application.
Test code:
Copy codeThe Code is as follows:
<Input type = button value = "click Start" onClick = "t = 5">
<Span id = "view"> </span>
<Script>
T =-1; // counter
SetInterval ("testTime ()", 1000); // 1 second scheduled startup
Function testTime (){
If (t <0) return; // the counter value is smaller than 0, indicating that the countdown has not started.
If (t = 0) // the counter value is 0.
Location = "http://www.jb51.net ";
View. innerHTML = "<B>" + t + "</B>"; // display the countdown
T --; // counter decrease
}
Function offTime (){
If (event. srcElement. value! = "Click Start") {// If the countdown is not started
T =-1; // Initial counter
View. innerHTML = ""; // clears the countdown
}
}
Document. onclick = offTime; // Start click event monitoring
</Script>

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.