I\'m dealing with a system where the following Javascript code (which is out of my control) is being executed early in the page
if (!(\"console\" in window)
Here is a method I wrote based on the previous answers. It's got a bit of extra logic so that you can call it multiple times without recreating the iframe.
function fixConsole() {
var iframe;
if(!(iframe = document.getElementById('fixConsole'))) {
iframe = document.createElement('iframe');
iframe.id = 'fixConsole';
document.body.appendChild(iframe);
}
delete console;
console = iframe.contentWindow.console;
};
I anticipate the need to call fixConsole
multiple times in the case that the code which originally redefined console
is self repairing.