自己的JS调试工具 myLogger()对象
2009-07-26 23:16
411 查看
/**
* @author elf
*/
function myLogger(id)
{
id=id||'ADSLogWindow';
var logWindow=null;
var createWindow=function(){
//取得新窗口在浏览器居中放置时左上角的位置
var browserWindowSize=ADS.getBrowserWindowSize();
var top=((browserWindowSize.height-200)/2)||0;
var left=((browserWindowSize.width-200)/2)||0;
//创建一个UL节点
logWindow=document.createElement('UL');
//指定ID ,以便在必要时在DOM树中能识别它
logWindow.setAttribute('id',id);
//在屏幕居中位置定位日志窗口
logWindow.style.position = 'absolute';
logWindow.style.top = top + 'px';
logWindow.style.left = left + 'px';
//设定固定的大小 ,并允许窗口内容滚动
logWindow.style.width = '200px';
logWindow.style.height = '200px';
logWindow.style.overflow = 'scroll';
logWindow.style.padding= '0';
logWindow.style.margin= '0';
logWindow.style.border= '1px solid black';
logWindow.style.backgroundColor= 'white';
logWindow.style.listStyle= 'none';
logWindow.style.font= '10px/10px Verdana, Tahoma, Sans';
//添加到文档主体中
document.body.appendChild(logWindow);
};
this.writeRaw=function(message){
if(!logWindow) createWindow();
//创建列表项并适当的添加样式
var li = document.createElement('LI');
li.style.padding= '2px';
li.style.border= '0';
li.style.borderBottom = '1px dotted black';
li.style.margin= '0';
li.style.color= '#000';
li.style.font = '9px/9px Verdana, Tahoma, Sans';
//为日志节点添加信息
if(typeof message == 'undefined') {
li.appendchild(document.createTextNode('Message was undefined'));
} else if(typeof li.innerHTML != undefined) {
li.innerHTML = message;
} else {
li.appendchild(document.createTextNode(message));
}
//添加'UL'窗口日志中
logWindow.appendChild(li);
return this;;
}
}
/**
* The myLogger prototype public methods
*/
myLogger.prototype = {
/**
* Writes a write a partially encoded version of the message to the log window.
* If the message is not a String, the toString method will be
* called on the object. If no toString() method exists, the typof
* will be logged.
* @param {Object} message
*/
write: function (message) {
// warn about null messages
if(typeof message == 'string' && message.length==0) {
return this.writeRaw('ADS.log: null message');
}
// if the message isn't a string try to call the toString() method,
// if it doesn't exist simply log the type of object
if (typeof message != 'string') {
if(message.toString) return this.writeRaw(message.toString());
else return this.writeRaw(typeof message);
}
// transform < and > so that .innerHTML doesn't parse the message as HTML
message = message.replace(/</g,"<").replace(/>/g,">");
return this.writeRaw(message);
},
/**
* Writes a simple header to the log window.
*/
header: function (message) {
message = '<span style="color:white;background-color:black;font-weight:bold;padding:0px 5px;">' + message + '</span>';
return this.writeRaw(message);
}
};
if(!window.ADS) { window['ADS'] = {}; }
window['ADS']['log'] = new myLogger();
if(!console) var console = ADS.log;
转自:http://elf8848.javaeye.com/blog/383422
* @author elf
*/
function myLogger(id)
{
id=id||'ADSLogWindow';
var logWindow=null;
var createWindow=function(){
//取得新窗口在浏览器居中放置时左上角的位置
var browserWindowSize=ADS.getBrowserWindowSize();
var top=((browserWindowSize.height-200)/2)||0;
var left=((browserWindowSize.width-200)/2)||0;
//创建一个UL节点
logWindow=document.createElement('UL');
//指定ID ,以便在必要时在DOM树中能识别它
logWindow.setAttribute('id',id);
//在屏幕居中位置定位日志窗口
logWindow.style.position = 'absolute';
logWindow.style.top = top + 'px';
logWindow.style.left = left + 'px';
//设定固定的大小 ,并允许窗口内容滚动
logWindow.style.width = '200px';
logWindow.style.height = '200px';
logWindow.style.overflow = 'scroll';
logWindow.style.padding= '0';
logWindow.style.margin= '0';
logWindow.style.border= '1px solid black';
logWindow.style.backgroundColor= 'white';
logWindow.style.listStyle= 'none';
logWindow.style.font= '10px/10px Verdana, Tahoma, Sans';
//添加到文档主体中
document.body.appendChild(logWindow);
};
this.writeRaw=function(message){
if(!logWindow) createWindow();
//创建列表项并适当的添加样式
var li = document.createElement('LI');
li.style.padding= '2px';
li.style.border= '0';
li.style.borderBottom = '1px dotted black';
li.style.margin= '0';
li.style.color= '#000';
li.style.font = '9px/9px Verdana, Tahoma, Sans';
//为日志节点添加信息
if(typeof message == 'undefined') {
li.appendchild(document.createTextNode('Message was undefined'));
} else if(typeof li.innerHTML != undefined) {
li.innerHTML = message;
} else {
li.appendchild(document.createTextNode(message));
}
//添加'UL'窗口日志中
logWindow.appendChild(li);
return this;;
}
}
/**
* The myLogger prototype public methods
*/
myLogger.prototype = {
/**
* Writes a write a partially encoded version of the message to the log window.
* If the message is not a String, the toString method will be
* called on the object. If no toString() method exists, the typof
* will be logged.
* @param {Object} message
*/
write: function (message) {
// warn about null messages
if(typeof message == 'string' && message.length==0) {
return this.writeRaw('ADS.log: null message');
}
// if the message isn't a string try to call the toString() method,
// if it doesn't exist simply log the type of object
if (typeof message != 'string') {
if(message.toString) return this.writeRaw(message.toString());
else return this.writeRaw(typeof message);
}
// transform < and > so that .innerHTML doesn't parse the message as HTML
message = message.replace(/</g,"<").replace(/>/g,">");
return this.writeRaw(message);
},
/**
* Writes a simple header to the log window.
*/
header: function (message) {
message = '<span style="color:white;background-color:black;font-weight:bold;padding:0px 5px;">' + message + '</span>';
return this.writeRaw(message);
}
};
if(!window.ADS) { window['ADS'] = {}; }
window['ADS']['log'] = new myLogger();
if(!console) var console = ADS.log;
转自:http://elf8848.javaeye.com/blog/383422
相关文章推荐
- 自己的JS调试工具 myLogger()对象
- 轻轻松松学JS调试(不下载任何工具)
- Js也有console对象,在控制台打印调试再好不过
- 谷歌浏览器开发调试工具中Sources面板 js调试等 完全介绍
- 发一个自己用JS写的实用看图工具
- 我的第一个JS组件-跨浏览器JS调试工具
- vue教程3-04 vue.js vue-devtools 调试工具的下载安装和使用
- ie下js调试超级爽的工具IE WebDeveloper V2 (附注册码)
- Console API 当打开 firebug (也包括 Chrome 等浏览器的自带调试工具),window 下面会注册一个叫做 console 的对象,它
- 推荐一个IE下的优秀js调试工具(Companion.JS)
- 员提供在线工具,提供jsbin在线 CSS、JS 调试,在线 Java API文档,在线 PHP API文档,在线 Node.js API文档,Less CSS编译器,...
- js调试工具
- 一个IE下的优秀js调试工具(Companion.JS)
- Js也有console对象,在控制台打印调试再好不过
- 使用python编写自己的进程调试工具
- IE中调试JS的一款很好的工具
- Plsql工具单步调试 存储过程或是 函数(oracle数据库)-留着自己用的
- 常用JS调试工具使用方法,帮你快速定位问题(Firebug+ IE“开发人员工具”)
- 自己动手封装js工具类(JS中定义类的几种方式)
- 定制自己的Log日志工具以及调试程序