settimeout function compatible with the main browser run execution effect instance _javascript skill

Source: Internet
Author: User
Currently this settimeout can be well compatible with ie6,7,8,9 as well as Google browser Chrome, Firefox firefox, Apple browser Safari,opera.

SetTimeout is a very good function, Site page front-end engineers often use it for a few seconds after the execution of the action. settimeout This JS built-in function is also very simple to use, the following is the settimeout () function description and usage details and examples, sample code:

The role of settimeout () is to specify how many milliseconds to execute a JS function or expression code
settimeout usage, syntax, parameters: settimeout (code,millisec)
SetTimeout parameter Description:
Code is a required parameter. The JavaScript code string to execute after the function to be invoked.
Millisec is a required parameter. The number of milliseconds to wait before executing the code. The conversion between milliseconds and seconds is: 1000 milliseconds = 1 seconds
SetTimeout Instance Code (page jumps to the specified URL after 1 seconds):
Copy Code code as follows:

<script language= "JavaScript" >
function Go () {//define Functions
Window.location= "main.html";//Page jump
}
Window.settimeout ("Go ()", 1000);//1 seconds to execute function go
</script>

But the above JS code is not compatible with Firefox, this is mainly because IE and Firefox browser engine is different. Let this section of the page Jump JS code compatible with IE, Firefox, SAFARI, OPERA:
Copy Code code as follows:

<script language= "JavaScript" >
function Go () {//define Functions
Window.location= "main.html";//Page jump
}
Window.settimeout (function () {go ()},1000);//1 seconds to execute functions go
</script>

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.