控制台对象的功能被覆盖后如何使用console.log()?

But*_*kus 1 javascript jquery console.log

我需要console.log(),但它不起作用,因为有人在生产站点中做了一些事情来阻止它.有没有其他方法可以打印到控制台?或者使用可以打印完整对象的警报,例如console.log()吗?或者重新定义console.log()以便它再次工作的方法?

我可以使用jQuery库.

rec*_*ive 7

根据他们阻止它的方式,你可以使用这样的东西.

    console.log = function fake() {};
    console.log("oh no! it's not working!")

    delete console.log;
    console.log("whew.  back again.");
Run Code Online (Sandbox Code Playgroud)

这只是删除了应用的自定义定义.

如果他们做了比这更聪明的事情,你可能会做这样的事情.这创造了一个iframe带有全新window物体的全新物品,您可以从中提取原始物体console.这仅在body元素已存在时才有效.

    var frame = document.createElement("iframe");
    frame.style.display = "none";
    document.body.appendChild(frame);

    var myConsoleLog = function(message) {
        (frame.contentWindow || frame).console.log(message);
    }
    myConsoleLog("this works too!");
Run Code Online (Sandbox Code Playgroud)