|
↑
Page Details >>>
The DOM Browser is a visual, interactive representation of the DOM (Document Object Model). It's helpful to beginners learning to interact with the DOM in JavaScript. It's also a great tool for side-by-side comparisons of Netscape, Internet Explorer, and other browsers and how they interpret the document and its elements.
Add the below code to the <body> section of your page:
<script
language="javascript"
type="text/javascript">
var
objects =
new
Array(),
browser =
null,
expanded =
null;
objects[0]
=
new
Array(document,
"_document",
false);
function
openDOMBrowser(activeElement){
activeIndex
=
arrayIndexOf(objects,
activeElement,
1);
objects[activeIndex][2]
=
!objects[activeIndex][2];
args
=
"width=500,height=600,left=20,top=20,scrollbars,resizable,top=0,left=0";
browser
=
window.open('',"DOMBrowser",args);
browser.focus();
expanded
=
new
Array();
expanded["_document"]
=
true;
browser.document.open("text/html","replace");
browser.document.writeln("<HTML><HEAD><TITLE>DOM
Browser</TITLE></HEAD>");
browser.document.writeln("<BODY
BGCOLOR=BBBBBB link=FFFFF vlink=FFFFF>");
browser.document.writeln("<h3>document:</h3><ul>");
getProps(document);
browser.document.writeln("</ul></BODY></HTML>");
browser.document.close();
return
false;
}
function
getProps(obj){
for(var
prop in
obj){
browser.document.writeln("<li>");
if(typeof(obj[prop])=="object"
&&
obj[prop]!=null){
valIndex
=
arrayIndexOf(objects,
obj[prop],
0);
if(valIndex==-1){
valIndex
=
objects.length;
key
=
((new
Date()).getTime()%10000)
+
"_"
+
(Math.floor(Math.random()*10000));
objects[valIndex]
=
new
Array(obj[prop],
key,
false);
}
browser.document.writeln("<b>"+prop+
"</b> : <a
href=\"javascript:void(0)\" onClick=\"window.opener.openDOMBrowser('"+
objects[valIndex][1]+"');return
false;\">"+(new
String(obj[prop])).replace(/</g,"<")+"</a>");
if(objects[valIndex][2]
&&
!expanded[objects[valIndex][1]]){
expanded[objects[valIndex][1]]
=
true;
browser.document.writeln("<ul>");
getProps(obj[prop]);
browser.document.writeln("</ul>");
}
}
else
browser.document.writeln("<b>"+prop+"</b>
: "
+
(new
String(obj[prop])).replace(/</g,"<"));
browser.document.writeln("</li>");
}
}
function
arrayIndexOf(array,
value,
field){
var
found =
false;
var
index
=
0;
while(!found
&&
index
<
array.length){
if(array[index][field]==value)
found
=
true;
else
index++;
}
return
(found)?index:-1;
}
</script>
<form>
<input
type=button
value="Open
DOM Browser"
onClick="openDOMBrowser('_document');">
</form>
|
→
|