I.E. first pops my JS script, then I press F12 and it works hit

I have a JS script that works fine in all browsers. But for everyone, in IE it does not work on the first try.

If after loading my page I press F12 (open the ie debugger) and refresh my page, it works great! Like other browsers! But for this job I need to press F12.

Does the debugger respond when we open it? I can not find a solution!

Thanks in advance.

+5
source share
4 answers

, IE , , console.log, undefined. F12, , console.log undefined.

, :

if (!window.console) window.console = {};
if (!window.console.log) window.console.log = function () { };

, .log , , , " ", undefined.

js ( ), .

+12

- console.log() script? , , F12

+2

Extended version from previous post

if (!('console' in window)) {
    var stub = function() { ; };
    window.console = {
        log : stub,
        info : stub,
        warn : stub,
        error : stub,
        assert : stub
    };
}

I am sending this new one which installs a stub only if necessary

/**
 * On IE console is not set if not opened and debug doesn't exists
 */
(function() {
    if (!('console' in window)) { window.console = {}; }
    var kind = ['log', 'info', 'warn', 'error', 'assert', 'debug'];
    var stub = function() { ; };
    for (var i = 0; i < kind.length; i++) {
        if (kind[i] in window.console) { continue; }
        window.console[kind[i]] = stub;
    }
})();
+2
source

You guys should check this question and the accepted answer for a detailed explanation: Does IE9 support console.log and is this a real feature?

0
source

All Articles