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

How to implement timed page jump in javascript

青灯夜游
Release: 2023-01-07 11:41:51
Original
6153 people have browsed it

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';
}
Copy after login

Optimization code:

// 五秒以后再跳转
setTimeout("javascript:location.href='https://www.php.cn'", 5000);
Copy after login

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)
Copy after login
ParameterDescription
codeRequired. The string of JavaScript code to be executed after the function to be called.
millisecRequired. 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
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template