Solution to the incompatible failure of JS settimeout function in Firefox browser _javascript tips

Source: Internet
Author: User
Today, check yourself with jquery+ajax+php do the website background login detection, found that after the successful landing page jump function this javascript (JS) code effects in IE and Google browser Chrome can be well executed, compatibility is not bad. Results to the Firefox (Firefox) browser settimeout This JS built-in function does not execute, invalid, also did not complain! Open Firebug hope it can detect JS error, the result is useless ... Javascript (JS) script code in the browser compatible is a very headache, after a debugging and search, and finally resolved the settimeout this JS code in Firefox under the failure of incompatible and can not run and execute errors. 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>

After watching. Bai [kankanbei.com] webmaster test, it is perfectly compatible with the mainstream browser, hereby write to share with you. It is noteworthy that the implementation of page jump JS code We are accustomed to writing location.href= page address, and this code in Firefox is also not run, you need to write window.location= page address.

Firefox browser under the JS code incompatible settimeout function Invalid not run execution solution

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.