ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Javascript Console.log在Chrome或Firefox中不起作用

2019-11-22 08:35:08  阅读:607  来源: 互联网

标签:logging firefox google-chrome wordpress javascript


我做的很简单:

console.log("Testing");

随着 :

alert("testing");

警报有效(因此我知道javascript正在工作),但是我看不到日志.当我使用Firefox时,出现以下错误:

The Web Console logging API (console.log, console.info,
console.warn, console.error) has been disabled by a script on this
page.

到底是怎么回事?我查看了以下主题,但没有帮助:

Chrome: console.log, console.debug are not working

console.log quit working in Chrome

Console.log not working in Chrome [closed]

why does console.log not output in chrome?
Console.log not working at all

我还确保该漏斗正在运行并且已打开日志记录.

还有什么问题呢?

解决方法:

我在Firefox更新后才遇到此问题,并设法解决了该问题.这是导致问题的代码:

/* IE fix that allows me to still log elsewhere */
if (typeof(console)=="undefined") {
    var console = {
        output: null,
        log: function (str) {
            // we can't emulate the console in IE, but we can cache what's output
            // so that IE users can get it via console.output
            if (!this.output) this.output = new Array();
            this.output.push(new String(str));
        }
    };
    window.console = console;
}

在FireFox的先前版本中,“ var console;”不会被执行.现在,它似乎已经添加了某种分支/预测机制.看到我可以使用全局范围定义一个名为console的变量,它禁用了window.console.

我通过重命名var console来解决此问题;到var cons;

/* IE fix that allows me to still log elsewhere */
if (typeof(console)=="undefined") {
    var cons = {
        output: null,
        log: function (str) {
            // we can't emulate the console in IE, but we can cache what's output
            // so that IE users can get it via console.output
            if (!this.output) this.output = new Array();
            this.output.push(new String(str));
        }
    };
    window.console = cons;
}

不过,我仍然需要对此进行测试,以确保它能够达到我在IE中的预期.我只需要查找没有控制台的IE副本(我认为9或以下).

我只希望Firefox可以告诉您什么脚本禁用了控制台-那就太好了.

标签:logging,firefox,google-chrome,wordpress,javascript
来源: https://codeday.me/bug/20191122/2058368.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有