5 ways to jump through HTML pages

Source: Internet
Author: User
Tags setinterval

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

123456 <head><!-- 以下方式只是刷新不跳转到其他页面 --><metahttp-equiv="refresh" content="10"><!-- 以下方式定时转到其他页面 --><metahttp-equiv="refresh" content="5;url=hello.html"> </head>

Advantages: Simple
Cons: Not available in Struts tiles

2) Implementation of JavaScript

123456 < Code class= "JavaScript plain" ><script language= "javascript" type= "Text/javascript" > //direct jump ' hello.html ' ; //The following way to a timed jump settimeout ( </SCRIPT>

Advantages: Flexible, can combine with more other functions
Cons: Affected by different browsers
3) combined with a reciprocal JavaScript implementation (IE)

123456789 < span id=" Totalsecond ">5</ span > < script language= " JavaScript "type=" Text/javascript "> var second = Totalsecond.innertext; setinterval ("redirect ()", +); function redirect () { totalsecond.innertext=--second; if (second< 0 } </SCRIPT>

Advantages: More Humane
Cons: Firefox does not support (Firefox does not support innertext attributes for span, Div, etc.)
3 ') combined with a countdown to the JavaScript implementation (Firefox)

123456789 <script language="javascript" type="text/javascript"> var second = document.getElementById(‘totalSecond‘).textContent; setInterval("redirect()", 1000); function redirect() { document.getElementById(‘totalSecond‘).textContent = --second; if (second < 0) location.href = ‘hello.html‘; } </script>

4) solve the problem that Firefox does not support innertext

12345678 <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>

5) Integration 3) and 3 ')

123456789101112131415161718192021222324 <span id="totalSecond">5</span><script language="javascript" type="text/javascript"> var second = document.getElementById(‘totalSecond‘).textContent; if (navigator.appName.indexOf("Explorer") > -1)  {     second = document.getElementById(‘totalSecond‘).innerText; } else {     second = document.getElementById(‘totalSecond‘).textContent; } setInterval("redirect()", 1000); function redirect() { 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.