Restoring console.log()

后端 未结 8 2398
粉色の甜心
粉色の甜心 2020-11-29 22:25

For some reason, the prototype framework (or another JavaScript code) that is shipped with Magento is replacing standard console functions, so I can\'t debug anything. Writi

8条回答
  •  粉色の甜心
    2020-11-29 22:34

    function restoreConsole() {
      // Create an iframe for start a new console session
      var iframe = document.createElement('iframe');
      // Hide iframe
      iframe.style.display = 'none';
      // Inject iframe on body document
      document.body.appendChild(iframe);
      // Reassign the global variable console with the new console session of the iframe 
      console = iframe.contentWindow.console;
      window.console = console;
      // Don't remove the iframe or console session will be closed
    }
    

    Tested on Chrome 71 and Firefox 65

提交回复
热议问题