Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to silence console output on an 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 */ };
}

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

like image 989
André Fratelli Avatar asked Feb 19 '15 08:02

André Fratelli


1 Answers

a working fiddle here

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

This works on Mozilla,Chrome ,Safari

like image 143
Vladu Ionut Avatar answered Sep 20 '22 18:09

Vladu Ionut