Solution: JS setTimeout Function incompatibility failure and not execution in Firefox browser

Source: Internet
Author: User

Today, I checked my website background login Detection Using JQuery + AJAX + PHP. After I found that the login was successful, I executed the page Jump function section JavaScript (JS) code effects can be executed well in IE and Google Chrome, And the compatibility is good. As a result, the JS built-in function setTimeout in FireFox is not executed. It is invalid and no error is reported! Open FireBUG and expect it to detect JS errors. The result is useless... the compatibility of Javascript (JS) script code in various browsers is a headache. After some debugging and searching, finally, the error of running and executing the setTimeout JS Code in Firefox is solved. Currently, this setTimeout is compatible with IE6, 9, Google Chrome, FireFox, Apple Safari, and Opera.

SetTimeout is a very good function, which is often used by front-end engineers on the website pages in a few seconds. SetTimeout: The JS built-in function is also easy to use. The following describes the setTimeout () function and its usage and examples and sample code:

SetTimeout () is used to specify how many milliseconds a JS function or expression code will be executed
SetTimeout usage, syntax, and parameter: setTimeout (code, millisec)
SetTimeout parameter description:
Code is a required parameter. The JavaScript code string to be executed after the function to be called.
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 second
SetTimeout instance Code (the page jumps to the specified URL in 1 second ):
Copy codeThe Code is as follows:
<Script language = "javascript">
Function go () {// define a function
Window. location = "main.html"; // page Jump
}
Window. setTimeout ("go ()", 1000); // execute the function go in 1 second
</Script>

However, the above JS Code is not compatible with Firefox, mainly because IE is different from Firefox's browser engine. Make this page Jump JavaScript code compatible with IE, Firefox, SAFARI, and OPERA:
Copy codeThe Code is as follows:
<Script language = "javascript">
Function go () {// define a function
Window. location = "main.html"; // page Jump
}
Window. setTimeout (function () {go ()}, 1000); // execute the function go in 1 second
</Script>

After reading the test by the webmaster of. Bei [kankanbei.com], it is perfectly compatible with mainstream browsers and is hereby written to share with you. It is worth noting that we are used to writing the JS Code for page Jump. href = page address, and this Code cannot run under Firefox. You need to write windows. location = page address.

The JS Code in Firefox is incompatible with the setTimeout function, which is invalid and does not run.

Related Article

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.