自己的JS调试工具 myLogger()对象

 伦理片 http://www.dotdy.com/
Java代码   收藏代码
  1. /** 
  2.  * @author elf 
  3.  */  
  4. function myLogger(id)  
  5. {  
  6.     id=id||'ADSLogWindow';  
  7.     var logWindow=null;  
  8.     var createWindow=function(){  
  9.         //取得新窗口在浏览器居中放置时左上角的位置  
  10.         var browserWindowSize=ADS.getBrowserWindowSize();  
  11.         var top=((browserWindowSize.height-200)/2)||0;  
  12.         var left=((browserWindowSize.width-200)/2)||0;  
  13.         //创建一个UL节点  
  14.         logWindow=document.createElement('UL');  
  15.         //指定ID ,以便在必要时在DOM树中能识别它  
  16.         logWindow.setAttribute('id',id);  
  17.         //在屏幕居中位置定位日志窗口  
  18.         logWindow.style.position = 'absolute';  
  19.         logWindow.style.top = top + 'px';  
  20.         logWindow.style.left = left + 'px';  
  21.         //设定固定的大小 ,并允许窗口内容滚动  
  22.         logWindow.style.width = '200px';  
  23.         logWindow.style.height = '200px';  
  24.         logWindow.style.overflow = 'scroll';  
  25.         logWindow.style.padding= '0';  
  26.         logWindow.style.margin= '0';  
  27.         logWindow.style.border= '1px solid black';  
  28.         logWindow.style.backgroundColor= 'white';  
  29.         logWindow.style.listStyle= 'none';  
  30.         logWindow.style.font= '10px/10px Verdana, Tahoma, Sans';  
  31.           
  32.         //添加到文档主体中  
  33.         document.body.appendChild(logWindow);         
  34.     };  
  35.     this.writeRaw=function(message){  
  36.         if(!logWindow) createWindow();  
  37.         //创建列表项并适当的添加样式  
  38.         var li = document.createElement('LI');  
  39.         li.style.padding= '2px';  
  40.         li.style.border= '0';  
  41.         li.style.borderBottom = '1px dotted black';  
  42.         li.style.margin= '0';  
  43.         li.style.color= '#000';  
  44.         li.style.font = '9px/9px Verdana, Tahoma, Sans';  
  45.         //为日志节点添加信息  
  46.         if(typeof message == 'undefined') {  
  47.             li.appendchild(document.createTextNode('Message was undefined'));  
  48.         } else if(typeof li.innerHTML != undefined) {  
  49.             li.innerHTML = message;  
  50.         } else {  
  51.             li.appendchild(document.createTextNode(message));  
  52.         }  
  53.         //添加'UL'窗口日志中  
  54.         logWindow.appendChild(li);  
  55.           
  56.         return this;;  
  57.     }  
  58. }  
  59.   
  60. /** 
  61.  * The myLogger prototype public methods 
  62.  */  
  63. myLogger.prototype = {  
  64.   
  65.     /**  
  66.      * Writes a write a partially encoded version of the message to the log window. 
  67.      * If the message is not a String, the toString method will be  
  68.      * called on the object. If no toString() method exists, the typof 
  69.      * will be logged. 
  70.      * @param {Object} message 
  71.      */  
  72.     write: function (message) {  
  73.         // warn about null messages  
  74.         if(typeof message == 'string' && message.length==0) {  
  75.             return this.writeRaw('ADS.log: null message');  
  76.         }  
  77.   
  78.         // if the message isn't a string try to call the toString() method,  
  79.         // if it doesn't exist simply log the type of object  
  80.         if (typeof message != 'string') {  
  81.             if(message.toString) return this.writeRaw(message.toString());  
  82.             else return this.writeRaw(typeof message);  
  83.         }  
  84.   
  85.         // transform < and > so that .innerHTML doesn't parse the message as HTML  
  86.         message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;");  
  87.   
  88.         return this.writeRaw(message);  
  89.     },  
  90.   
  91.   
  92.     /** 
  93.      * Writes a simple header to the log window. 
  94.      */   
  95.     header: function (message) {  
  96.         message = '<span style="color:white;background-color:black;font-weight:bold;padding:0px 5px;">' + message + '</span>';  
  97.         return this.writeRaw(message);  
  98.     }  
  99.   
  100. };  
  101.   
  102. if(!window.ADS) { window['ADS'] = {}; }  
  103. window['ADS']['log'] = new myLogger();  
  104. if(!console) var console = ADS.log;  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值