5 ways to jump through HTML pages

Source: Internet
Author: User

The following is a list of five examples in detail, the main function of these examples is: after 5 seconds, automatically jump to the same directory hello.html (according to their own needs to modify) files.

1) Implementation of HTML

<Head><!--The following methods just refresh do not jump to other pages -<Metahttp-equiv= "Refresh"content= "Ten"><!--go to another page in the following way -<Metahttp-equiv= "Refresh"content= "5;url=hello.html"> </Head>

Advantages: Simple
Cons: Not available in Struts tiles

2-1) JavaScript implementation [LOCATION.HREF]

<Scriptlanguage= "JavaScript"type= "Text/javascript"> //jump directly in the following wayswindow.location.href='hello.html';//The following methods are timed to jumpSetTimeout ("javascript:location.href= ' hello.html '",  the); </Script>

The SetTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.

Advantages: Flexible, can combine with more other functions
Cons: Affected by different browsers

2-2) combined with a reciprocal JavaScript implementation (IE)

<spanID= "Totalsecond">5</span><Scriptlanguage= "JavaScript"type= "Text/javascript"> varSecond=Totalsecond.innertext; SetInterval ("Redirect ()",  +); functionRedirect () {Totalsecond.innertext=--second;if(Second<0) Location.href='hello.html'; } </Script>

The SetInterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds).

The SetInterval () method keeps calling functions until Clearinterval () is called or the window is closed. The ID value returned by SetInterval () can be used as a parameter to the Clearinterval () method.

Advantages: More Humane
Cons: Firefox does not support (Firefox does not support innertext attributes for span, Div, etc.)

2-3) combined with the countdown to the JavaScript implementation (Firefox)

<Scriptlanguage= "JavaScript"type= "Text/javascript"> varSecond=document.getElementById ('Totalsecond'). textcontent; SetInterval ("Redirect ()",  +); functionRedirect () {document.getElementById ('Totalsecond'). Textcontent= --second;if(Second< 0) Location.href= 'hello.html'; } </Script>

2-4) solve the problem that Firefox does not support innertext

<spanID= "Totalsecond">5</span><Scriptlanguage= "JavaScript"type= "Text/javascript"> if(Navigator.appName.indexOf ("Explorer") > -1) {document.getElementById ('Totalsecond'). InnerText= "my text InnerText"; } Else{document.getElementById ('Totalsecond'). Textcontent= "my text textcontent"; } </Script>

2-5) compatible with reciprocal jumps for IE and FF

<spanID= "Totalsecond">5</span> <Scriptlanguage= "JavaScript"type= "Text/javascript"> varSecond=document.getElementById ('Totalsecond'). textcontent; if(Navigator.appName.indexOf ("Explorer") > -1) {Second=document.getElementById ('Totalsecond'). InnerText; } Else{Second=document.getElementById ('Totalsecond'). textcontent; } setinterval ("Redirect ()",  +); functionRedirect () {if(Second< 0) {Location.href= 'hello.html'; } Else {     if(Navigator.appName.indexOf ("Explorer") > -1) {document.getElementById ('Totalsecond'). InnerText=Second--; } Else{document.getElementById ('Totalsecond'). Textcontent=Second--; } } } </Script>

5 ways to jump through HTML pages

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.