|
Name:
|
ObjectInfo |
|
Level:
|
Beginner |
|
Language:
|
JavaScript 1.2 |
|
Functionality:
|
Lets the user choose a JavaScript object from a select list, and find out what properties are associated with that object. |
|
Use:
|
Demonstration of how to get the information given when an object is created. |
| <form name="propForm">
Please select an object from the list: <select name = "objectList"> <option selected value="Window">Window <option value="Date">Date <option value="Document">Document <option value="Form">Form <option value="Image">Image <option value="Link">Link <option value="Navigator">Navigator </select> <input type=button value="click me" onClick=whichObject(this.form.objectList)> </form> |
The HTML code for the form is shown above. The form is named propForm,
and contains a selection list with the names of different objects.
When the button is clicked, the select list object is passed as a parameter
to the whichObject function.
| function whichObject(list) {
var object = ""; var listValue = getListValue(list); var newWindow = window.open("","","HEIGHT=400,WIDTH=350,status=1,resizable=1,scrollbars=1") newWindow.document.write("<HTML><HEAD><TITLE>"+listValue+"</TITLE></HEAD></HTML>") switch (listValue) { case "Window": object = window; break; case "Document": object = window.document; break; case "Form": object = window.document.propForm; break; case "Image": object = window.document.someImage; break; case "Link": object = window.document.links; break; case "Navigator": object = navigator; break; } newWindow.document.write(getProperties(object)); newWindow.document.close(); } |
| function getListValue(list)
{ var listValue = ""; if (list.selectedIndex != -1) {
return (listValue);
|
| function getProperties(obj) {
var properties = ""; properties = '<HTML><BODY><TABLE BORDER="2" WIDTH="90%" COLS="2">'; properties += '<TR ALIGN="left" BGCOLOR="lightgrey"><TH>Property</TH><TH>Value</TH></TR>'; for (var propName in obj) { properties +="<TR><TD>"+propName+"</TD><TD>"+obj[propName]+" </TD></TR>"; } properties +="</TABLE></BODY></HTML>"; return properties; } |
For the latest technical information on Sun-Netscape Alliance products, go to: http://developer.iplanet.com
For more Internet development resources, try Netscape TechSearch.
