Chrome“删除控制台” - 如何恢复?

时间:2015-11-04 09:54:40

标签: javascript google-chrome console console.log

可以在delete console

之后恢复Chrome控制台

Google Chrome版本:46.0​​.2490.80 m

在以前的版本中,此命令恢复原始控制台,但现在我收到消息:

  

未捕获的ReferenceError:未定义控制台

1 个答案:

答案 0 :(得分:1)

嗯,这很容易,而且已经被问到了:

function healConsole() {
  //<iframe> element
  var iframe = document.createElement("iframe");
  //Hide it somewhere
  iframe.style.position="fixed";
  iframe.style.height = iframe.style.width = "1px";
  iframe.style.top = iframe.style.left = "-5px";
  //No src to prevent loading some data
  iframe.src = "about: blank";
  //Needs append to work
  document.body.appendChild(iframe);
  //Get the inner console
  window.console = iframe.contentWindow.console;
}

最初在这里问:Get access to the console once the console object reference was changed