Home  >  Article  >  Web Front-end  >  How to implement timed page jump in javascript

How to implement timed page jump in javascript

青灯夜游
青灯夜游Original
2021-07-02 16:07:476147browse

In javascript, you can use setTimeout() with the href attribute of the location object to implement the scheduled page jump function. The syntax format is "setTimeout("javascript:location.href=jump page address", milliseconds) ;".

How to implement timed page jump in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Javascript implements scheduled jump page

// 五秒以后再跳转
setInterval("myInterval()",5000);//1000为1秒钟
function myInterval()
{
  window.location.href='/crm/php/mail/editmail.php';
}

Optimization code:

// 五秒以后再跳转
setTimeout("javascript:location.href='//m.sbmmt.com'", 5000);

Description:

setTimeout() The method is used to call a function or calculated expression after a specified number of milliseconds. The syntax format is as follows:

setTimeout(code,millisec)
Parameter Description
code Required. The string of JavaScript code to be executed after the function to be called.
millisec Required. The number of milliseconds to wait before executing code.

window.location.href The property is a readable and writable string that can set or return the complete URL of the currently displayed document.

Therefore, we can make the browser read and display the content of the new URL by setting a new URL for this property.

Grammar

location.href=URL

[Related recommendations: javascript learning tutorial]

The above is the detailed content of How to implement timed page jump in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn