Home  >  Article  >  Web Front-end  >  The setTimeout function is compatible with all mainstream browsers and has execution effects examples_javascript skills

The setTimeout function is compatible with all mainstream browsers and has execution effects examples_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:32:251316browse

Currently, this setTimeout is well compatible with IE6, 7, 8, 9, as well as Google Chrome, Firefox, Safari, and Opera.

setTimeout is a very good function. Website page front-end engineers often use it for actions that will be executed after a few seconds. The setTimeout JS built-in function is also very simple to use. The following is the function description of setTimeout(), detailed usage, examples, and sample code:

The function of setTimeout() is to specify how many milliseconds to execute a JS function or Expression code
Usage, syntax, and parameters of setTimeout: setTimeout(code,millisec)
setTimeout parameter description:
code is a required parameter. The string of JavaScript code to be executed after the function to be called.
millisec is a required parameter. The number of milliseconds to wait before executing code. The conversion between milliseconds and seconds is: 1000 milliseconds = 1 second
setTimeout example code (the page jumps to the specified URL after 1 second):

Copy code The code is as follows:



But the above JS code is not compatible with Firefox. This is mainly because the browser engines of IE and Firefox are different. Make this page jump JS code compatible with IE, Firefox, SAFARI, and OPERA:
Copy the code The code is as follows:


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