本文介紹了覆蓋后訪問window.console的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
console.log 被覆蓋后是否可以通過某種方式訪問??它?
Is it possible to somehow access to console.log after it gets overwritten?
window.console = { log: function (msg) { alert(msg); }, /* etc... */ };
能否恢復原來的 console.log 功能?
Would be it be possible to regain the original console.log functionality?
推薦答案
您可以在覆蓋之前備份控制臺.
You can back up the console before overwriting it.
var oldConsole = window.console;
window.console = { log:function(msg){alert(msg)} //...};
然后你可以使用 oldConsole
變量.
Then you can use the oldConsole
variable.
oldConsole.log('test');
如果無法備份,可以創建 iFrame,然后從那里竊取控制臺(這可能不適用于所有瀏覽器):
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;
演示:http://jsfiddle.net/jcG7E/2
這篇關于覆蓋后訪問window.console的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!