Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to somehow access to console.log after it gets overwritten?

window.console = { log: function (msg) { alert(msg); }, /* etc... */ };

Would be it be possible to regain the original console.log functionality?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
136 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can back up the console before overwriting it.

var oldConsole = window.console;
window.console = { log:function(msg){alert(msg)} //...};

Then you can use the oldConsole variable.

oldConsole.log('test');

If you can't back it up, you can create an iFrame, and then steal the console from there (this may not work in all browsers):

var i = document.createElement('iframe');
i.style.display = 'none';
document.body.appendChild(i);
window.console = i.contentWindow.console;

Demo: http://jsfiddle.net/jcG7E/2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...