


JavaScript implements automatic jump to a page after x seconds_javascript skills
May 16, 2016 pm 05:44 PMI learned a new technology while watching a video today, that is, when we click "Submit" or "Confirm" on a page, it will automatically jump to a page.
After searching on the Internet, there are many ways to deal with this technology. I only wrote down the three methods I learned in the video:
1. Use a response.sendRedirect("target page.jsp.htm "); to achieve direct jump;
2. Sometimes we need some prompts, such as "It will jump automatically after x seconds. If there is no jump, please click here", you can call Delay Go in Snippets in myeclipse To URL. The following code will be automatically generated:
<script language="JavaScript1.2" type="text/javascript">
<!--
// Place this in the 'head' section of your page.
function delayURL(url, time ) {
setTimeout("top.location.href='" url "'", time);
}
//-->
</script>
< !-- Place this in the 'body' section -->
<a href="javascript:" onClick="delayURL('myPage.html','2000')">My Delayed Link</ a>
Modify this code to:
<script language="JavaScript1.2" type="text/javascript">
function delayURL(url, time) {
setTimeout("top.location.href='" url "'", time);
}
</script>
<span id="time" style="background: red">3</span>
seconds later Automatically jump, if not, please click the link below
<a href="target page.jsp">target page</a>
<script type="text/javascript"> ;
delayURL("http://www.hualai.net.cn", 3000);
</script>
Then it will jump directly after 3 seconds Go to the "Target Page". This method is to set a few seconds to jump and the page will not change during this process. For example, set it to 3 seconds, and then as time changes, 3 turns to 2 and then to 1 until it jumps. Please follow Look at the third method.
3. Modify the code in method 2 to:
<script language="JavaScript1.2" type="text/javascript">
function delayURL(url) {
var delay=document.getElementById("time").innerHTML;
//The last innerHTML cannot be lost, otherwise delay is an object
if(delay>0){
delay--;
document.getElementById("time").innerHTML=delay;
} else{
window.top.location.href=url;
}
setTimeout("delayURL('" url "')", 1000);
//1000 milliseconds here is every Jump once per second
}
</script>
<span id="time" style="background: red">3</span>
Automatically jump after seconds , if it does not jump, please click the link below
<a href="target page.jsp">topic list</a>
<script type="text/javascript">
delayURL("http://www.hualai.net.cn/news/knowledge/265.html");
</script>
The effect achieved by this method is After clicking submit on the previous page, you will jump to this page. After 3 seconds (this 3 will decrease to 0), you will jump to the target page.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of PHP page jump function: page jump skills of header, location, redirect and other functions

How to implement page jump after PHP form submission

How to log in and jump to pass value in php

How to implement page jump in 3 seconds: PHP Programming Guide

How to implement PHP code to jump to a specified page

PHP programming skills: How to jump to the web page within 3 seconds

Use uniapp to achieve page jump animation effect
