programing

Internet Explorer에서 콘솔 로깅을 사용하려면 어떻게해야합니까?

new-time 2020. 7. 18. 23:48
반응형

Internet Explorer에서 콘솔 로깅을 사용하려면 어떻게해야합니까?


IE 용 콘솔 로거가 있습니까? 콘솔에 많은 테스트 / 어설 션을 기록하려고하지만 IE 에서이 작업을 수행 할 수 없습니다.


"개발자 도구"(F12)를 시작하여 IE8 스크립트 콘솔에 액세스 할 수 있습니다. "스크립트"탭을 클릭 한 다음 오른쪽의 "콘솔"을 클릭하십시오.JavaScript 코드 내에서 다음 중 하나를 수행 할 수 있습니다.

<script type="text/javascript">
    console.log('some msg');
    console.info('information');
    console.warn('some warning');
    console.error('some error');
    console.assert(false, 'YOU FAIL');
</script>

또한을 호출하여 콘솔을 지울 수 있습니다

console.clear()

.

참고 :

이 기능을 사용하려면 먼저 개발자 도구를 시작한 다음 페이지를 새로 고쳐야합니다.


버전 8부터 Internet Explorer에는 다른 브라우저와 마찬가지로 자체 콘솔이 있습니다. 그러나 콘솔을 사용

console

하지 않으면 개체가 존재하지 않고 호출

console.log

하면 오류가 발생합니다.또 다른 옵션은

log4javascript

(전체 공개 : 나 작성)를 사용하는 것인데, IE> = 5를 포함한 모든 주류 브라우저에서 작동하는 자체 로깅 콘솔과 undefined 문제를 피하는 브라우저 자체 콘솔 래퍼가

console

있습니다.


프로덕션 환경에서 console.log ()를 사용하는 경우 매우 중요합니다.

 

console.log()

명령을 프로덕션으로 릴리스 하면 IE에 대한 일종의 수정이 필요 합니다. 디버깅 모드

console

에서만 정의 되기 때문 입니다

F12

.

if (typeof console == "undefined") {
    this.console = { log: function (msg) { alert(msg); } };
}

[분명히 alert (msg)를 제거하십시오. 작동이 확인되면 진술]

참조

'콘솔'Internet Explorer 용 정의되지 않은 오류가

다른 솔루션 및 자세한 내용은


IE에는 많은 Firebug 기능을 제공하는

Firebug Lite

가 있습니다 .


다른 브라우저에 대한 줄 번호 매기기를 유지하는 간단한 IE7 이하 심 :

/* console shim*/
(function () {
    var f = function () {};
    if (!window.console) {
        window.console = {
            log:f, info:f, warn:f, debug:f, error:f
        };
    }
}());

John Resig (jQuery의 제작자)는 그의 저서 "Javascript Ninja의 비밀"에서 크로스 브라우저 console.log 문제를 처리 할 수있는 간단한 코드를 가지고 있습니다. 그는 모든 브라우저에서 작동하는 로그 메시지를 원한다고 설명했으며 다음과 같이 코딩했습니다.

function log() {
  try {
    console.log.apply(console, arguments);
  } catch(e) {
  try {
    opera.postError.apply(opera, arguments);
  }
  catch(e) {
    alert(Array.prototype.join.call( arguments, " "));
  }
}

console.log (디버그, 추적 등)로 제한된 IE8 또는 콘솔 지원의 경우 다음을 수행 할 수 있습니다.

  • console OR console.log가 정의되지 않은 경우 : 콘솔 함수 (추적, 디버그, 로그 등)에 대한 더미 함수를 작성하십시오.

    window.console = { debug : function() {}, ...};

  • console.log가 정의되어 있고 (IE8) console.debug (기타)가 정의되어 있지 않은 경우 : 모든 로깅 기능을 console.log로 리디렉션하면 로그를 유지할 수 있습니다!

    window.console = { debug : window.console.log, ...};

Not sure about the assert support in various IE versions, but any suggestions are welcome.


You can use cross-browser wrapper: https://github.com/MichaelZelensky/log.js


For older version of IE (before IE8), it is not straight forward to see the console log in IE Developer Toolbar, after spending hours research and trying many different solutions, finally, the following toolbar is great tool for me:

The main advantage of this is providing a console for IE6 or IE7, so you can see what are the error (in the console log)

  • Note:
  • It is free
  • screen shot of the toolbar

enter image description here

참고URL : https://stackoverflow.com/questions/2656730/how-can-i-use-console-logging-in-internet-explorer

반응형