Web page automatic Jump Implementation method PHP, JSP (bottom) _javascript tips

Source: Internet
Author: User

This paper discusses several implementation methods of Web page automatic jump.
Method one: Using the META tag meta tag is one of the indispensable tags of HTML, which is responsible for providing meta information about the document, and its parameters include:
①HTTP-EQUIV: HTTP file header related to data in document
②content: Data related to the named HTTP header
③name: Document Description
④url: URL associated with meta information when we define the attribute http-equiv for refresh, the system will jump to the corresponding page within a certain period of time according to the value specified in the content, content= "seconds; url= url" is to define too much time to jump to the specified URL. The following meta tags tell the system one second after the page automatically jumps to the Dark Horse online power:
<meta http-equiv= "Refresh" content= "1;url=http://www.jb51.net/" >
The above code needs to be added to the HTTP document header, between This method is common to any environment and contains static web space.
Method Two: Using the header function header function is one of the HTTP correlation functions in the PHP built-in function, which sends out HTTP protocol headers to the browser. With it, you can redirect URLs to other specified pages. The following example, after the implementation will automatically open the Dark Horse online power home:
Header ("location:http://www.jb51.net/");
It is important to note that the header function can only be used before the

Copy Code code as follows:

<?php
/* Login program-filename: login.php
Program role-To determine the user login password * *
if ($_post[' Submit ']) {
Session_Start ();
if ($_post[' PWS ']== ' 123 ') {//If the password is 123
$_session[' passwd ']= ' 123 '; Write session data
Header ("Location:index.php"); Jump to normal page
}else{
Header ("Location:login.php"); Jump to login Page
}
}
The form code is slightly (you can also write the form in pure HTML code, and if so, the code should be placed after the program
?>
<?php
/* Detect session Data-filename: index.php
Program action-detects if the password in session data is 123, if not, return
Login Page * *
Session_Start ();
if ($_session[' passwd ']!= ' 123 ') header ("Location:login.php");
Other code (pure HTML code should be written after the program)
?>

This method is obviously only used to support the space environment of PHP.
Method Three: Use Javascriptjs is very flexible, use it can make the function very powerful program script, here only a simple page to jump the JS example. After the following code is executed, the browser will automatically go to the Dark Horse Online power website, which can be placed in any legal position on the page:
<script language= "javascript" type= "Text/javascript" > Window.location.href ("http://www.jb51.net"); </ Script> This code applies to any Web environment. Adding a timer would be even more fantastic.

Frequently encountered problems with automatic page jumps for example, in some sites need to exit the login to appear a prompt page
What, you're quitting a kind of polite, and some have to make a rewind.
Method One:
<meta http-equiv= "Refresh" content= "Wait Time"; Url= ' jump page ' >
Method Two:
This is a JS application.
Test code:
Copy Code code as follows:

<input Type=button value= "click Start" onclick= "t=5" >
<span id= "View" ></span>
<script>
t =-1; Counter
SetInterval ("Testtime ()", 1000); Start 1 seconds at timed time
function Testtime () {
if (t<0) return; Counter value is less than 0, indicating that the countdown has not been started
if (t = = 0)//Counter value is 0, turn to
Location = "Http://www.jb51.net";
view.innerhtml = "<b>" +t+ "</b>"; Show Countdown
t--; Counter Decrement
}
function Offtime () {
if (Event.srcElement.value!= "click Start") {//If the countdown does not start
t =-1; Initial counter
view.innerhtml = ""; Clear 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.