我的页面使用iframe来显示一些内容,但是现在我正在使用主页面,而iframe的输出正在混乱我的控制台并使其难以调试.有没有办法让控制台静音?
我尝试将控制台设置为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 */ };
}
Run Code Online (Sandbox Code Playgroud)
我希望这可以工作,但iframe仍然会产生输出.
工作小提琴这里
var iframe = document.createElement('iframe');
iframe.setAttribute("src", "yourIframeURL");
document.body.appendChild(iframe);
iframeWindow = iframe.contentWindow;
iframeWindow.console.log = function() { /* nop */ };
Run Code Online (Sandbox Code Playgroud)
这适用于Mozilla,Chrome,Safari
| 归档时间: |
|
| 查看次数: |
2488 次 |
| 最近记录: |