如何使iframe上的控制台输出静音 [英] How to silence console output on an iframe

查看:295
本文介绍了如何使iframe上的控制台输出静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面正在使用iframe显示一些内容,但是现在我在主页上工作,iframe的输出使控制台混乱,难以调试.有什么方法可以使控制台静音?

My page is using iframes to display some content, but right now I'm working on the main page and the output from the iframes is cluttering my console and making it hard to debug. Is there any way to silence the console?

我尝试将控制台设置为无操作:

I tried setting the console to a no-op:

var CONSOLE_LOG = window.console.log;
window.console.log = function() { /* nop */ };

function LOG(msg)
{
    window.console.log = CONSOLE_LOG;
    console.log(msg);
    window.console.log = function() { /* nop */ };
}

我希望它能起作用,但是iframe仍会生成输出.

I expected this to work, but the iframes still generate output.

推荐答案

有用的小提琴此处

var iframe = document.createElement('iframe');
iframe.setAttribute("src", "yourIframeURL");
document.body.appendChild(iframe);
iframeWindow = iframe.contentWindow;
iframeWindow.console.log = function() { /* nop */ };

这适用于Mozilla,Chrome,Safari

This works on Mozilla,Chrome ,Safari

这篇关于如何使iframe上的控制台输出静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆