JavaScript code causes IE incompatibilities due to comma _javascript tips

Source: Internet
Author: User

In the use of ExtJS to do front-end development, the discovery system can be in Google Browser, Firefox under normal display, but with IE browser Open will be an error, error information such as: expected identified, string or number. Later, check the code when found, is due to the JS code in the comma is not the norm caused by IE incompatible.

Since I write code in Eclipse, I'll explain how to use eclipse to solve this problem:

For example, there is a section of code that is not canonical:

Ext.onready (function () {
var panel = ext.create (' Ext.container.Viewport ', { 
layout: ' Border ',
items: [{ C4/>title: ' North Panel ',
HTML: "North Content",
region: ' North ',
height:100,
}, {
title: ' West Panel ',
HTML: ' West content ',
region: ' West ',
width:150,//This is remark 1
}, {
title: ' Main Panel ', c15/>html: ' main content ',
region: ' Center ',/
* This is remark 2*/
}]
;

Can see, in 100, 150, center behind have a comma (,), run with IE, in fact, will be an error. So since the code has been written like this, how to detect this problem!


Figure 1:file Search

As shown in Figure 1 above, you can use the Eclipse's File search feature to search with regular expressions, with the regular expression \s*}. However, there is a problem, can only retrieve the first error above, for added//or/**/to annotate the situation, is not detected. However, you can also use yuicompressor such as the JS Code compression tool to compress the code, when the compression will be all of the comments removed, and then to detect the compressed JS file can be. Of course, you can also write your own algorithm to detect, however, this is still difficult for ordinary people!

However, I suggest another way, is to use plug-ins, I use here is the Spket plug-in, Spket's official website is: http://www.spket.com/, you can go inside to download Spket eclipse Plug-ins, can also be directly in Eclipse market download, download after the installation of this plugin, and then the JS file with Spket Open.


Figure 2: Using Spket detection

As shown in Figure 2 above, you can find that the Spket automatically detect the code is not standardized, where there are problems are labeled out, I suggest this method, because you can write the code, the discovery of problems, to help write code beautiful codes! Another mention, some times the compatibility is because the use of the object is IE does not exist, such as console objects, in Firefox and Google exist, but in IE use console.info on the error! So, remember to remove some incompatible objects from the code!

The above to introduce the JavaScript code because of the comma does not standardize the problem of IE incompatible, I hope to help you!

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.