이후 콘솔드로그 개발자 도구를 열었을 때만 사용할 수 있습니다 (F12 로 전환하십시오 열고 단힌 정보기술 (it). 재미있는 것은, ve 연 후 you& # 39 닫으십시오 수 있습니다 다음 포스트에 콘솔드로그 통해 이를 다시 열 때, 이러한 페이징됩니다 여전히 볼 수 있을 것으로 보인다.
function trace(s) {
if ('console' in self && 'log' in console) console.log(s)
// the line below you might want to comment out, so it dies silent
// but nice for seeing when the console is available or not.
else alert(s)
}
심지어 간단해진다는:
function trace(s) {
try { console.log(s) } catch (e) { alert(s) }
}
이건 내 시행하십시오 다양한 대한 답변. 실제로 보지 않은 싶었다 로깅된 메시지, 설령 내가 IE 콘솔입니다 오픈 때, 그래서 나는 그들에게 '' 내가 총격을 붙여넣습니다 콘솔스메사주 누름식 어레이입니다 작성. 난 또 ' ()' 을 더 편리하게 볼 수 있는 기능이 추가된 콘솔스트럼프 전체 로그에서는. 메시지 큐 () '은' 콘솔.클리어 비우기.
이 솔루션은 handles" "; 다른 콘솔입니다 서버리스 (I believe) 에서 시작된 있는 모든 방화범 콘솔입니다 apiu)
마지막으로, 이 솔루션은 형태로 세계 내시경이요 더럽히지 않기 때문에 인생 대체 인수는 하단의 정의된 함수 코드입니다.
난 그냥 내 마스터에는 드롭합니다 JS 파일을 포함되어 있으며, 이는 모든 페이지에 잊어버려.
(function (fallback) {
fallback = fallback || function () { };
// function to trap most of the console functions from the FireBug Console API.
var trap = function () {
// create an Array from the arguments Object
var args = Array.prototype.slice.call(arguments);
// console.raw captures the raw args, without converting toString
console.raw.push(args);
var message = args.join(' ');
console.messages.push(message);
fallback(message);
};
// redefine console
if (typeof console === 'undefined') {
console = {
messages: [],
raw: [],
dump: function() { return console.messages.join('\n'); },
log: trap,
debug: trap,
info: trap,
warn: trap,
error: trap,
assert: trap,
clear: function() {
console.messages.length = 0;
console.raw.length = 0 ;
},
dir: trap,
dirxml: trap,
trace: trap,
group: trap,
groupCollapsed: trap,
groupEnd: trap,
time: trap,
timeEnd: trap,
timeStamp: trap,
profile: trap,
profileEnd: trap,
count: trap,
exception: trap,
table: trap
};
}
})(null); // to define a fallback function, replace null with the name of the function (ex: alert)
(인수), '선' 에서 '는 var args = 아리스프로토리 페이즐리체스콜 어레이에서는 인수의 객체를. 인수만 것은 정말 어레이에서는 때문에 이 필요합니다.
' ()' 는 기본 처리기에서 트랩할 대해서는 apiu 총괄하였습니다. 나는 메시지를 전달할 수 있도록 로그를 인수 '' 에 전달된 주장은 모든 API 호출 (콘솔드로그 '아니라').
내가 또 '정확히' 는 '가 추가 어레이입니다 콘솔드로 인수만 전달된 트랩할 ()'. 아니라는 사실을 깨달은 아리스스타인 (& # 39. ' & # 39;) '는', '어떤 개체를 문자열 변환 " [객체객체] " 원하지 않는 경우도 많다. 제안 의 브폰테인 감사합니다.
var console=console||{"log":function(){}};
I really like the 외곽진입 올린 orange80" ";). # 39 의 우아한 it& 때문에 한 번 집어쳐요 설정할 수 있습니다.
다른 방법으로 다른 일을 합니다 (call '일반' 콘솔드로그 () 이외의 모든 시간), 이는 결국 내가 알고 있는 것을 그냥 문제 해결을 위해 I&; d # 39 잊어라.
<! - 모든 언어: > js 랭 -;
/**
* Call once at beginning to ensure your app can safely call console.log() and
* console.dir(), even on browsers that don't support it. You may not get useful
* logging on those browers, but at least you won't generate errors.
*
* @param alertFallback - if 'true', all logs become alerts, if necessary.
* (not usually suitable for production)
*/
function fixConsole(alertFallback)
{
if (typeof console === "undefined")
{
console = {}; // define it if it doesn't exist already
}
if (typeof console.log === "undefined")
{
if (alertFallback) { console.log = function(msg) { alert(msg); }; }
else { console.log = function() {}; }
}
if (typeof console.dir === "undefined")
{
if (alertFallback)
{
// THIS COULD BE IMPROVED… maybe list all the object properties?
console.dir = function(obj) { alert("DIR: "+obj); };
}
else { console.dir = function() {}; }
}
}
어떤 브라우저를 위한 최적의 솔루션을 없는 콘솔입니다 입니다.
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});
while (length--) {
method = methods[length];
// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
}
}());
너무 많아 분입니다. 내 솔루션이므로 엔드입니다 없었다.
globalNamespace.globalArray = new Array();
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
console.log = function(message) {globalNamespace.globalArray.push(message)};
}
한마디로 콘솔드로그 doesn& 존재하는 경우, t # 39 (또는 이 경우 연 isn& # 39, t) 을 저장하는 로그인하십시오 노드전역 이름공간이 어레이입니다. 즉, 수백만 개의 경고 및 you& # 39, re 필터링되지 졸라 댔 너회의 로깅합니다 열거나 닫을 수 있는 개발자 콘솔입니다 보실 수 있습니다.
내가 찾은 이 on 깃허브:
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f() {
log.history = log.history || [];
log.history.push(arguments);
if (this.console) {
var args = arguments,
newarr;
args.callee = args.callee.caller;
newarr = [].slice.call(args);
if (typeof console.log === 'object') log.apply.call(console.log, console, newarr);
else console.log.apply(console, newarr);
}
};
// make it safe to use console.log always
(function(a) {
function b() {}
for (var c = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), d; !! (d = c.pop());) {
a[d] = a[d] || b;
}
})(function() {
try {
console.log();
return window.console;
} catch(a) {
return (window.console = {});
}
} ());
내가 여기서 찾을 수 있는 솔루션 (https://stackoverflow.com/a/7967670) 나 혼합 제대로 개체 표시.
즉, 함수 트랩할 됩니다.
function trap(){
if(debugging){
// create an Array from the arguments Object
var args = Array.prototype.slice.call(arguments);
// console.raw captures the raw args, without converting toString
console.raw.push(args);
var index;
for (index = 0; index < args.length; ++index) {
//fix for objects
if(typeof args[index] === 'object'){
args[index] = JSON.stringify(args[index],null,'\t').replace(/\n/g,'<br>').replace(/\t/g,' ');
}
}
var message = args.join(' ');
console.messages.push(message);
// instead of a fallback function we use the next few lines to output logs
// at the bottom of the page with jQuery
if($){
if($('#_console_log').length == 0) $('body').append($('<div />').attr('id', '_console_log'));
$('#_console_log').append(message).append($('<br />'));
}
}
}
이것은 도움됐네 좋겠다)
Make your own 콘솔입니다 html. -) 임프라베드 수 있지만 이 작업을 시작할 수 있습니다.
if (typeof console == "undefined" || typeof console.log === "undefined") {
var oDiv=document.createElement("div");
var attr = document.createAttribute('id'); attr.value = 'html-console';
oDiv.setAttributeNode(attr);
var style= document.createAttribute('style');
style.value = "overflow: auto; color: red; position: fixed; bottom:0; background-color: black; height: 200px; width: 100%; filter: alpha(opacity=80);";
oDiv.setAttributeNode(style);
var t = document.createElement("h3");
var tcontent = document.createTextNode('console');
t.appendChild(tcontent);
oDiv.appendChild(t);
document.body.appendChild(oDiv);
var htmlConsole = document.getElementById('html-console');
window.console = {
log: function(message) {
var p = document.createElement("p");
var content = document.createTextNode(message.toString());
p.appendChild(content);
htmlConsole.appendChild(p);
}
};
}
맘에 드는 방법 (jquery& 사용하여 # 39 의 doc 준비됐어들). 심지어 콘솔입니다 ie 에서 사용할 수 있습니다. # 39 만 페이지를 열면 잘 필요한 것은 리로드하려면 ie& 후, s 개발 툴 페이지 로드되는지.
하지만 난 의해 모든 기능을 사용할 수 있다면 그렇게 야바위꾼 차지 로깅합니다 이게 나는한다.
//one last double check against stray console.logs
$(document).ready(function (){
try {
console.log('testing for console in itcutils');
} catch (e) {
window.console = new (function (){ this.log = function (val) {
//do nothing
}})();
}
});
다음은 콘솔에 로그 버전 될 때 열고 닫을 때 개발자 도구는 아니다.
(function(window) {
var console = {};
console.log = function() {
if (window.console && (typeof window.console.log === 'function' || typeof window.console.log === 'object')) {
window.console.log.apply(window, arguments);
}
}
// Rest of your application here
})(window)