Summary of regular page Jump code using javascript

Source: Internet
Author: User

In js, it is easy to directly use window to achieve page Jump. location. href can be implemented. If you want to perform a scheduled jump, you need to use the setTimeout Function to set a scheduled jump. I will summarize it for you.

The following is a summary of the regular page Jump (also called countdown jump) using JavaScript. Various regular jump code records are as follows:

Common page Jump code

First:

The Code is as follows: Copy code

<Script language = "javascript">

Window. location. href = "index. php ";

// There are no commonly used methods to explain. You can directly specify the place to jump.

</Script>

Second:

 

The Code is as follows: Copy code

<Script language = "javascript">

Alert ("return ");

Window. history. back (-1 );

// Similar to a button, if the parameter is a negative value, it will be regressed several times.

</Script>

Third:

 

The Code is as follows: Copy code

<Script language = "javascript">

Window. navigate ("index. jsp ");

// The navigate object contains information about the browser. It can also be used as a page Jump, followed by a place to jump directly.

// The public standard is not applied to the navigator object, but all browsers support this object.

</Script>

Fourth:

 

The Code is as follows: Copy code

<Script language = "JavaScript">

Self.location.href?index.htm;

// Self refers to the current window object, which belongs to the upper-level window object;

// Location. href indicates the URL address of a window object.

// Self. location. href indicates the URL address of the current window. Remove self as the URL address of the current window by default.

</Script>

 

Page Jump code

(1) Use the setTimeout Function to implement timed jump (the following code should be written in the body area)
 

The Code is as follows: Copy code

 

<Script type = "text/javascript">
// Jump to the specified page 3 seconds later
SetTimeout (window. location. href = "http://www.bKjia. c0m", 3 );
</Script>

(2) html code implementation. Add the following code to the header area of the page:

 

The Code is as follows: Copy code

 

<! -- Jump to the specified page in 5 seconds -->

<Meta http-equiv = "refresh" content = "5; url = http://www.bKjia. c0m"/>

(3) It is a little complex, most often seen in timed jump after login

 

The Code is as follows: Copy code

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> js page Jump method </title>
</Head>
<Body>
<Script type = "text/javascript">
Var t = 10; // set the jump time
SetInterval ("refer ()", 1000); // 1 second scheduled startup
Function refer (){
If (t = 0 ){
Location = "http://www.bKjia. c0m"; // set the link address of the jump
}
Document. getElementById ('show '). innerHTML = "" + t + "seconds later, jump to php programmer tutorial"; // display countdown
T --; // counter decrease
}
</Script>
<Span id = "show"> </span>
</Body>
</Html>

(4) page redirection using php header has achieved the purpose of regular page Jump

 

The Code is as follows: Copy code

 

<? Php
/**
@ Title: PHP implements timed jump
@ Function: Wait for the specified time and jump to the specified page (instead of html meta)
*/
Header ("refresh: 3; url = http://www.bKjia. c0m ");
Echo 'loading. Please wait... <br> automatic jump in 3 seconds ';
/*
Note: If the wait time is 0, it is equivalent to header ("location.
*/
?>

The page displays the timer jump for countdown

The Code is as follows: Copy code


<Script type = "text/javascript">

StartTime (); // call a function

Var I =-1; // Initialization

Var t;

Function startTime ()

I ++; // calculate the number of Recursion

Var m = 20; // The initial value is 20 minutes.

Var s = 0; // The initial second is 0.

M = checkTime (Math. floor (60 * m-I * 0.5)/60); // display the number of minutes and then normalize them.

S = checkTime (Math. floor (60 * m-I * 0.5) % 60); // display the number of seconds and then normalize them.

If (m = 0 & s = 0)

ClearTimeout (t); // set the stop time.

Top. window. location = "Logout. aspx"; // jump to the new page from the overall page of the framework

Else

Document. getElementById ('D'). innerHTML = m + ":" + s; // display the countdown in the span with id = d

T = setTimeout ('starttime () ', 500); // the set time is changed every 0.5 seconds.

Function checkTime (I) // display the Standard Time

If (I <10)

{I = "0" + I}

Return I;

</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.