Home > Article > Web Front-end > Solution to the syntax error or missing object problem reported by IE6 when introducing JS files_javascript skills
Solve the problem of "IE6 error when importing JS files"
Problem description:
The page introduces a js file, which defines a function or object, and then calls the function in the page or object, "Syntax error" or "Missing object" will be reported in IE6. It runs normally in IE6 or IE7.
Problem analysis:
This object exists in the imported JS file because it can run normally in browsers above IE6. This problem lies in the file encoding. If the JS file encoding is inconsistent with the encoding of the current page, it may cause the page in IE6 to be unable to properly obtain and parse the content in the JS file. In IE6, the encoding of the file imported by default is the same as that of the page. of. In browsers above IE6, general browsers will automatically identify the encoding of each external file and parse it;
Problem solution:
1: Introduce js files Add the charset attribute to keep it consistent with the page encoding;
Two: Modify the encoding format of the imported file;
Three: Create a new file with the same format as the page encoding, copy and paste the content;
(Personally recommend the third option Method, but it is recommended to add the charset attribute when importing js! )
Found the problem:
Due to reinstalling the system, I found js error after publishing the project: Syntax error There are also missing objects. Depressed
The system used to be ie7, but after reinstalling the system it was ie6. At first I thought it was a browser version problem, thinking that the js imported into the page contained code that was incompatible with ie6! So I finally commented out the js line by line. When all the js files were finally deleted, the above error still appeared. ------Super depressing
The code was fine before, but it broke after reinstalling the system. Finally, I found out that the previous project was released. There were no errors under IE6, and the code was exactly the same. ----------I wonder if I can still use the word "depressed"?
After thinking about it for a long time, I came up with the coding problem. In the past, the project encoding was gb2312, but now the project has been changed to UTF-8
and it has no effect after adding it. Even if the encoding format of js is changed to UTF-8, it will not work either. Finally, create a new js file and change the encoding format to utf-8, and publish OK.
Faint, general coding modification (1). Add charset. (2). Modify the file encoding format. I also checked under tomcat and it has been modified. I don’t know what’s going on!
Maybe I’ll delete it all before posting it! ! ! But the problem is finally solved~ If I didn’t reinstall the system, I still wouldn’t have discovered this little bug ----Make a note of it to prevent this kind of error from happening in the future!