Solve the ewebeditor old version of the new version of IE button failure problem once and for all methods

Source: Internet
Author: User

The unit has a set of news release system, is a long time ago, has been in use, what version of Ewebeditor is also confused, but certainly the old version.

A period of time also has a problem, in the IE8 button failure, after Baidu, the solution is almost all the same, are a variety of judgment IE version and then execute the corresponding anonymous method.

What's wrong is this sentence in editor.js: if (element. Yuseronclick) eval (element. Yuseronclick + "anonymous ()");

And the solution, without exception, is two kinds of

1.

1  if (Navigator.appVersion.match (/msie (7|8) \./i)!=null | | navigator.appVersion.match (/maxthon/i) = = ' MAXTHON ') 2 {3     if (element. Yuseronclick) eval (element. Yuseronclick + "onclick (event)"); 4}else{5     if (element. Yuseronclick) eval (element. Yuseronclick + "anonymous ()"); 6}

The program with version detection method, for different versions of IE, call different function names to solve, but the problem is that the subsequent version of IE popular up and add version number to judge, if IE modified the function name will be more trouble to judge.

2.

12345678910 if   { try { eval_r (element. Yuseronclick +  catch   (e) { eval_r (element. Yuseronclick +  "anonymous ()" ) ; }
This method does not detect the IE version number, but through the Try/catch to blur the version number, the same problem, when IE changed the function name again, it is also nested a layer of try/catch.

3. This is the solution I've designed.

Turning over the network, it seems that only these two solutions, it seems to be turned around into a standard solution. Personal view, these two methods of code too much to say, and can not deal with IE upgrade after the possibility of changing the function name again. Careful analysis of the problematic code will reveal that the element is in fact. The Yuseronclick attribute contains a function definition, and alert will see the code string as follows:

1234 functionanonymous(){//这里是执行代码}

In a complete view, the use of eval to execute a JS code snippet is as follows:

12345 functionanonymous(){//这里是执行代码}anonymous()

Because of the changes in IE's upgrade, the Anonymous () function name changes, but we use the function name as a constant string in the code, this change can not adapt.

Of course, we can also use the method of extracting characters to separate the function name from the code snippet, and then piece together the code snippet to execute, although the method is not a problem, but not concise enough.

In fact, using the dynamic characteristics of JS, we can completely do not need to know the function name and do not need to dynamically extract the function name of the case directly execute the function

The final code will save code bytes more than the source code, and simply replace the function name with a pair of parentheses to resolve it:

if(element.YUSERONCLICK) eval("("+ element.YUSERONCLICK + ")()");

Such a processing, not only add code, but lose weight, and no matter what the function name becomes after IE upgrade version does not matter, as long as IE does not cancel this anonymous function function will be once and for all .

4, about the PostScript of this article

Two years later today (2014-10-20) again, due to an anonymous function failure of an older version of Ewebeditor, the blog was again turned out. Bored to Whipple net search the keyword "ewebeditor", before a bright found a paper quoted the solution in this blog post, time is in this blog post finishing the same year (2012).

Dizzy Ah, a classmate quoted this article incredibly has not known AH.

Hereby remark, meet a little vanity, at least our blog is also a reference to the literature, on the grade, oh yes y.

Solve the ewebeditor old version of the new version of IE button failure problem once and for all methods

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.