![]() | |
#1
| |||
| |||
|
#2
| |||||||||||
| |||||||||||
|
|
Debugger.js 1.0 This is my Javascript debugger. |
|
What it does: After you displaying the debug window (see tip 1) you can move your mouse over any element on the page and the window will populate with all the properties, events, and objects of that element. ^^^ |
|
Instructions: Place the following line in your page you wish to debug: script language="JavaScript" src="js/Debugger.js"></script Tips: 1. You can make the debug window appear by pressing "ctrl+shift+d" |
|
2. You can stop the debug window from following your mouse by pressing ctrl |
|
3. You can click on a object listed in the object tag and the debug window will populate with that objects data |
|
4. You can click on the property name, event name, or the word msdn on the object tab to goto the msdn definition of that property. |
|
You can freely use this with only one condition, credit goes to me. That mean if you tell your boss you wrote this, I will hunt you down and feed your ears to my pet sloth. PS: Please post any impovement to this thread. Thx document.onmousemove = document_onmousemove; document.onkeypress = document_onkeypress; var lastobject; var currenttab = "properties"; var keyspressed = false; var lastx; var lasty; snip |
|
function document_onmousemove(){ |
|
try{ if (!event.ctrlKey){ lastx = event.clientX + 10; lasty = event.clientY + 10; |
|
//cell tab properties var td=document.createElement('td'); td.style.borderRight = 'gray 1px solid'; td.style.borderTop = 'gray 1px solid'; td.style.borderLeft = 'gray 1px solid'; td.innerText='Properties'; td.style.textAlign='center'; td.style.cursor = 'hand'; td.style.padding='2px'; td.onclick = buildProperties; tr.appendChild(td); //cell tab events var td=document.createElement('td'); td.style.borderRight = 'gray 1px solid'; td.style.borderTop = 'gray 1px solid'; td.style.borderLeft = 'gray 1px solid'; td.style.borderBottom = 'gray 1px solid'; td.innerText='Events'; td.style.textAlign='center'; td.style.cursor = 'hand'; td.style.padding='2px'; td.onclick = buildEvents; tr.appendChild(td); //cell tab objects var td=document.createElement('td'); td.style.borderRight = 'gray 1px solid'; td.style.borderTop = 'gray 1px solid'; td.style.borderLeft = 'gray 1px solid'; td.style.borderBottom = 'gray 1px solid'; td.innerText='Objects'; td.style.textAlign='center'; td.style.cursor = 'hand'; td.style.padding='2px'; td.onclick = buildObjects; tr.appendChild(td); |
|
//cell tab properties var td2=document.createElement('td'); td2.style.borderRight = 'gray 1px solid'; td2.style.borderTop = 'gray 1px solid'; td2.style.borderLeft = 'gray 1px solid'; td2.innerText='Properties'; td2.style.textAlign='center'; td2.style.padding='2px'; td2.colSpan = '2'; tr2.appendChild(td2); snip var results = new String(eval("theobject." + prop)); snip |
#3
| |||
| |||
|
|
Robert Skidmore wrote: Debugger.js 1.0 This is my Javascript debugger. Debugger is probably the wrong name for this. From a debugger I expect the ability to single step through (and over) code, set break points, inspect the value of variables and the like. What you have created is probably better termed and object inspector or DOM Node inspector, and certainly could be a valuable aid in debugging browser scripts. Indeed IMO writing (or at least attempting to write) a cross-browser object inspector can be a very valuable learning exercise as the more complete it becomes the more it has the potential to bring you face to face with each of the oddities exhibited by any individual browser. And a familiarity with browser DOMs in depth makes handling their diversity easier. What it does: After you displaying the debug window (see tip 1) you can move your mouse over any element on the page and the window will populate with all the properties, events, and objects of that element. ^^^ As you are using a - for(prop in obj) - loop the most you can claim is that all of the ennumerable properties of an object will be reported. But what is wrong with reporting methods in addition to (non object and event handler) properties, properties that refer to objects and event handlers? (incidentally, the distinction you are drawing between properties, events and objects is arbitrary, possibly misleading, and ultimately wrong. They are all properties.) I observer, for example, that an attributes collection has a length property of, say 86, but you are not listing any of those integer indexed properties (which do actually refer to objects). Instructions: Place the following line in your page you wish to debug: script language="JavaScript" src="js/Debugger.js"></script Tips: 1. You can make the debug window appear by pressing "ctrl+shift+d" But twice in rapid succession and a script error results (more caution is called for). 2. You can stop the debug window from following your mouse by pressing ctrl You should describe this a holding Ctrl down, but maybe you should change the implementation to a toggle. However, your window makes no allowance for the possibility that the page is scrolled. 3. You can click on a object listed in the object tag and the debug window will populate with that objects data That feature could do with a "back" button of some sort. 4. You can click on the property name, event name, or the word msdn on the object tab to goto the msdn definition of that property. Not when the browser is not on line. You can freely use this with only one condition, credit goes to me. That mean if you tell your boss you wrote this, I will hunt you down and feed your ears to my pet sloth. PS: Please post any impovement to this thread. Thx document.onmousemove = document_onmousemove; document.onkeypress = document_onkeypress; var lastobject; var currenttab = "properties"; var keyspressed = false; var lastx; var lasty; snip It is a pity that you did not observer the advice on posting code to Usenet offered in the FAQ. You have indented your code with Tab characters eve4n though it is known that newsreaders handle Tabs inconsistently. Mine for example ignores them, so your code is presented as not indented at all, but newsreaders that display tabs may be using an unsuitable number of space characters per-tab (the common default of 8 is really too many in a newsgroup post). You also have not done anything to control the way that your newsreader has wrapped your code, rendering it broken as presented. These problems can (and so should) be avoided. function document_onmousemove(){ This is a mouse move handler. Mouse move events are generated (and queued) for virtually every transition of the mouse form pixel to pixel. As a result the associated handlers must be fast (so usually simple) else they cannot keep up and become a bottleneck in the browser's event handling system. Your event handler is trying to do too much and the result is less than responsive. try{ if (!event.ctrlKey){ lastx = event.clientX + 10; lasty = event.clientY + 10; So this isn't even attempting to be cross-browser. That really makes in next to useless in an Internet authoring context. snip snip //cell tab properties var td=document.createElement('td'); td.style.borderRight = 'gray 1px solid'; td.style.borderTop = 'gray 1px solid'; td.style.borderLeft = 'gray 1px solid'; td.innerText='Properties'; td.style.textAlign='center'; td.style.cursor = 'hand'; td.style.padding='2px'; td.onclick = buildProperties; tr.appendChild(td); //cell tab events var td=document.createElement('td'); td.style.borderRight = 'gray 1px solid'; td.style.borderTop = 'gray 1px solid'; td.style.borderLeft = 'gray 1px solid'; td.style.borderBottom = 'gray 1px solid'; td.innerText='Events'; td.style.textAlign='center'; td.style.cursor = 'hand'; td.style.padding='2px'; td.onclick = buildEvents; tr.appendChild(td); //cell tab objects var td=document.createElement('td'); td.style.borderRight = 'gray 1px solid'; td.style.borderTop = 'gray 1px solid'; td.style.borderLeft = 'gray 1px solid'; td.style.borderBottom = 'gray 1px solid'; td.innerText='Objects'; td.style.textAlign='center'; td.style.cursor = 'hand'; td.style.padding='2px'; td.onclick = buildObjects; tr.appendChild(td); Do I observer the sort of repetition that might be better accommodated with a parameterised function call? snip //cell tab properties var td2=document.createElement('td'); td2.style.borderRight = 'gray 1px solid'; td2.style.borderTop = 'gray 1px solid'; td2.style.borderLeft = 'gray 1px solid'; td2.innerText='Properties'; td2.style.textAlign='center'; td2.style.padding='2px'; td2.colSpan = '2'; tr2.appendChild(td2); snip var results = new String(eval("theobject." + prop)); snip Using - eval - to resolve a dynamically created dot notation property accessor? It might be an idea to learn javascript if you are planning on scripting web browsers:- URL: http://jibbering.com/faq/#FAQ4_39 Richard. |
![]() |
| Thread Tools | |
| Display Modes | |
| |