tôi đã thực hiện để thực hành những điều sau đây trước khi DOM tải:
(function(window, undefined){
var debug_print = (location.search.indexOf('debug') != -1);
if(window['console'] == undefined){
var _logs = [];
var _console = {
log : function(){
_logs.push({'msg':Array.prototype.slice.call(arguments, 0), 'type':null});
this._out();
},
warn : function(){
_logs.push({'msg':Array.prototype.slice.call(arguments, 0), 'type':'warn'});
this._out();
},
error : function(){
_logs.push({'msg':Array.prototype.slice.call(arguments, 0), 'type':'error'});
this._out();
},
_out : function(){
if(debug_print && typeof this['write'] == 'function'){
this.write(_logs.pop());
}
},
_print : function(){return debug_print;},
_q : function(){return _logs.length;},
_flush : function(){
if(typeof this['write'] == 'function'){
_logs.reverse();
for(var entry; entry = _logs.pop();){
this.write(entry);
}
}
}
}
window['console'] = _console;
}
})(window)
và điều này sau khi domload (đặt nó ở phần cuối của thẻ nội dung):
(function(window, undefined){
if(window['console']){
if(console['_print']){
var console_pane = document.createElement('div');
console_pane.id = '_debug_console';
document.body.appendChild(console_pane);
console.write = function(log){
var msg = [new Date(), log.msg].join("$/> ");
var entry_pane = document.createElement('div');
if(log.type !== undefined){
entry_pane.className = log.type;
};
console_pane.appendChild(entry_pane);
entry_pane.innerHTML = msg;
};
console._flush();
};
}
})(window)
Điều này cho phép bạn thực hiện tất cả các điều cơ bản và tắt cơ chế hiển thị bảng điều khiển thực tế và bật với chuỗi truy vấn ?debug
(nó có thể được đặt ở bất kỳ đâu trong chuỗi truy vấn). Để làm cho nó trông ít tàn bạo bạn cũng có thể muốn nhóm trong css sau:
#_debug_console{
background : #ffffff;
margin: 0px;
position: fixed;
bottom: 0;
width: 100%;
height: 20%;
font-family: Arial;
font-size: 10px;
border-top: solid 5px #ddd;
}
#_debug_console .error{
color: #FF0000;
}
#_debug_console .warn{
color: #DDDD00;
}
★ Câu hỏi này được nhập hoàn toàn thông qua Nintendo Wii. ★ –
Nhận xét này được nhập hoàn toàn trên máy tính để bàn (chạy Opera). – Artelius
Tôi nhận được một số nhận xét đáng ngạc nhiên về meta.stackoverflow.com khi tôi nói rằng các phần của trang web không hoạt động trên trình duyệt Wii, vì vậy tôi chỉ muốn chỉ ra điều đó. –