Allow IE compatible console--"This operation cannot be completed due to error 80020101" solution

Source: Internet
Author: User

Problem description

The test found the problem only now:

1, native IE8 (other version IE simulated IE8 without this problem)

2, from open IE8 did not open the F12 (once opened and closed without this problem)

IE8 Error "This operation could not be completed because of errors 80020101", causing the current page to fail to display, while all the pages in the entire station could not be loaded.

Problem Analysis-IE8 No console object

From the above symptoms analysis, speculation should be related to IE8 developer tools, the code is used in the IE developer tools provided by the API interface or function, and when the F12 is not turned on, because there is no corresponding interface caused error.

By opening F12 Discovery to output the info information, it should be caused by the console.info () that is used in the code.

After inspection found IE8 under the F12 when not opened , Window object does not have console, then use console any method will error.

Solution-ie Constructing the empty console object

Add compatible code, if there is a console object in the current window using the current object, the new Window.console object is not present, and all the console functions are defined as empty functions. To ensure that the page does not error.

IE8-compatible Empty console object window.console = Window.console | | {    log: $.noop,    debug: $.noop,    info: $.noop,    warn: $.noop,    exception: $.noop,    assert: $.noop,    dir: $.noop,    dirxml: $.noop,    Trace: $.noop,    Group: $.noop,    groupcollapsed: $.noop,    GroupEnd: $.noop, Profile    : $.noop,    profileend: $.noop,    count: $.noop,    clear: $.noop, time    : $.noop,    timeend: $.noop,    timeStamp: $.noop,    table: $.noop,    error: $.noop};

When a compatible code is added, no error will be IE8 when the console is not available. Meimei.

New problem-console Object not complete

It didn't last long. The test team found that there are some IE8 version of this report, a look is still the console problem.

The test found that under certain IE8 versions, in the case where the F12 was never opened, the Window object had a console object under it, and the above compatible code was deceived, but only the log method in its console. The code used the Console.info, resulting in still error.

Test IE8 Consolevar str = "window.console:\n"; for (var i in window.console) {    str + = i + ":" + typeof (Window.console [i]) + "\ r \ n";} alert (str);

Operation Result:

wtf!

I can not change the code to detect console no contains info method, God knows which version of IE which method is compatible with the error method but not compatible with other functions?

It seems that the solution can only rewrite the console object

Final Solution-Override all console functions

The usual console functions are re-wrapped again, equivalent to the hook original function, internal judgment is available.

Window._console = window.console;//The original console object is cached Window.console = (function (orgconsole) {return {///constructed new console object Log:getconsolefn ("Log"), Debug:getconsolefn ("Debug"), Info:getconsolefn ("info"), Warn:getconso Lefn ("Warn"), Exception:getconsolefn ("Exception"), Assert:getconsolefn ("assert"), Dir:getconsolefn        ("dir"), Dirxml:getconsolefn ("Dirxml"), Trace:getconsolefn ("Trace"), Group:getconsolefn ("group"), Groupcollapsed:getconsolefn ("groupcollapsed"), Groupend:getconsolefn ("GroupEnd"), Profile:getconso Lefn ("Profile"), Profileend:getconsolefn ("Profileend"), Count:getconsolefn ("Count"), Clear:getcons Olefn ("clear"), Time:getconsolefn ("Time"), Timeend:getconsolefn ("Timeend"), Timestamp:getconsolefn ("TimeStamp"), Table:getconsolefn ("table"), Error:getconsolefn ("error"), Memory:getconsolefn ("Memo Ry "), MarktimelinE:getconsolefn ("Marktimeline"), Timeline:getconsolefn ("timeline"), Timelineend:getconsolefn ("Timelineend")    )    }; function Getconsolefn (name) {return function actionconsole () {if (typeof (Orgconsole)!== "Object") re            Turn if (typeof (Orgconsole[name])!== "function") return;//determine if the original console object contains this method, and if not, return directly to ORGCONSOLE[NAME].A    Pply (Orgconsole, Array.prototype.slice.call (arguments));//Call the original function}; }} (Window._console));

It solves all kinds of problems caused by the incomplete console object in IE, and does not affect the console function of the Advanced browser.

--June 11, 2015 19:06:45

Allow IE compatible console--"This operation cannot be completed due to error 80020101" 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.