/**
* @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;
* @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
分类:
06~javascript
, 06~js dom
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)