调试js用的对象属性显示器(原创)

发表于:2007-06-30来源:作者:点击数: 标签:
/* Ftiger 对象属性显示器 做用:显示浏览器对象,很多对象可能你听都没有听说过,对于调试js时无法找到对象有帮助。 使用:请将这个文件存为show_objec.js 在你要调试的页面中加上script src=show_objec.js/script 要查对象时请用 alt+o呼出查看界面 支持:
/*
Ftiger 对象属性显示器
做用:显示浏览器对象,很多对象可能你听都没有听说过,对于调试js时无法找到对象有帮助。
使用:请将这个文件存为show_objec.js
            在你要调试的页面中加上<script src="show_objec.js"></script>
            要查对象时请用 alt+o呼出查看界面
支持:目前只支持IE
参考:http://51js.1000box.net/51js-baoku/baoku/0142.htm (对象属性显示器 [木木鱼] )
注意:在页面中使用了document.onkeydown事件,如你的页面也使用这个事件,请注意


*/

document.write ("<div id=@#div_showWidowdObject@# name=@#div_showWidowdObject@# style=@#position:absolute;display:none@#>test</div>")
//
function ShowWidowdObjectStart()
    {var yy=100,xx=100;
     var ie=document.all?1:0;
     var nc=document.layers?1:0;

     var yy=0;
     var xx=0;
     var s_line="<tr bgcolor=#777777><td colspan=4 height=1></td></tr>";
     var s_vling="<td width=1 bgcolor=#777777></td>"
     if (ie)
        {yy=document.body.clientHeight;
         xx=document.body.clientWidth;
         div_showWidowdObject.style.top=(yy/2-150)+document.body.scrollTop;
         div_showWidowdObject.style.left=xx/2-300;
        };
      
      str_out=("<table width=@#600@# border=@#0@# cellspacing=@#0@# cellpadding=@#0@# bgcolor=@##eeeeee@# height=@#300@#><FORM METHOD=POST name=@#form_showWidowdObject@# onSubmit=@#Get_showWidowdObject();return false@#>"
      +s_line
      +"<tr>"+s_vling+"<td bgcolor=#eeeeee style=@#font-size:9.5pt@# colspan=2> Ftiger流览器对象查看器<td align=right style=@#font-size:9.5pt;cursor: hand;@# onClick=@#showWidowdObjectClose()@#>关闭</td>"+s_vling+"</tr>"
      +s_line
      +"<tr>"+s_vling+"<td style=@#font-size:9.5pt@#>当前对象:<INPUT TYPE=@#text@# NAME=@#text_showWidowdObject@# size=40> </td>"
      +"<td align=right  onClick=@#showWidowdObjectBack()@# style=@#font-size:9.5pt;cursor: hand;@#><font face=@#Webdings@#  style=@#font-size:13pt@#>7</Font></td><td align=right onClick=@#Get_showWidowdObject()@# style=@#font-size:9.5pt;cursor: hand;@# width=50>查看</td>"
      +s_vling+"</tr>"
      +s_line
      +"<tr>"+s_vling+"<td colspan=3 height=100%  valign=top style=@#font-size:9.5pt;@#><div id=@#Div_showWidowdObject_out@# name=@#Div_showWidowdObject_out@# style=@#font-size:9.5pt;width:100%; height:100%; overflow:auto;@#></div></td>"
      +s_vling+"</tr></FORM>"
      +s_line
      +"</table>");
      div_showWidowdObject.innerHTML=str_out;
      
    }
    function showWidowdObjectClose()
        { document.all.div_showWidowdObject.style.display    ="none"
        }
    function showWidowdObjectBack()
        {    str_ob=document.form_showWidowdObject.text_showWidowdObject.value    
            var i_end=str_ob.lastIndexOf(".")
             str_ob=str_ob.substr(0,i_end)
             Get_showWidowdObject(str_ob)
        }
    function Get_showWidowdObject(id)
        {str_obj=id?id:document.form_showWidowdObject.text_showWidowdObject.value;
         str_obj=(str_obj==""?"window":str_obj)
         try{
            eval("var obj="+(str_obj==""?"window":str_obj)+";");
            }
        catch(e){
            alert("输入错误,对象不存在,请重新输入!");
            document.form_showWidowdObject.text_showWidowdObject.value="";
            document.form_showWidowdObject.text_showWidowdObject.select();
            return(false);
                }
            document.form_showWidowdObject.text_showWidowdObject.value=     str_obj
        var j=0;
        var str_result="<table bgcolor=#000000 width=80% align=center border=@#0@# cellspacing=@#1@# cellpadding=@#3@#>";
        for (var i in obj)
            {j++;
             str_result+="<tr bgcolor=#ffffff style=@#font-size:9.5pt@#>"
            str_result+="<td>"+j+"</td>"
            str_result+="<td style=@#cursor: hand;@# onclick=@#Get_showWidowdObject(\""+str_obj+"."+i+"\")@#>"+i+"</td>"
            if ((""+i=="outerHTML")||(""+i=="innerHTML"))
                {str_result+="<td><Textarea Name=@#@# Rows=@#5@# Cols=@#30@# Name=@#@# >"+(""+obj[i])+"</textarea>"}    
                else
                {str_result+="<td>"+obj[i]+""}
            }
        obj=null
        str_result="对象:"+str_obj+ "<br>属性:"+j+"个"+str_result+"</table>"
        Show_showWidowdObject(str_result)
        
        }

    function Show_showWidowdObject (s_html)
        {Div_showWidowdObject_out.innerHTML=s_html
        
        }
    function showWidowdObjectOpen ()
        { var Keycord=event.keyCode
            //alert (Keycord)
           if (event.altKey && Keycord=="79")
            {
               document.all.div_showWidowdObject.style.display="block";
                ShowWidowdObjectStart();}
        }
    document.onkeydown=showWidowdObjectOpen

原文转自:http://www.ltesting.net