Java Script Quick Tutorial
2. Getting information
Summary :
1. Getting 'window' information, property by property
2. Getting 'document' information, property by property
3. Usefull function : ListAllProperties
4. Getting all 'window' information
5. Getting all 'document' information
1. Getting 'window' information,
property by property
General 'window' information ( manual ) :
Copy of the javascript code :
document.write ( "window.defaultStatus =
" + window.defaultStatus + "<br>" );
document.write ( "window.name = " + window.name + "<br>" );
document.write ( "window.opener = " + window.opener + "<br>" );
document.write ( "window.status = " + window.status + "<br>" );
Result :
'window.navigator' information ( manual ) :
Copy of the javascript code :
document.write ( "navigator.appCodeName
= " + navigator.appCodeName + "<br>" );
document.write ( "navigator.appName = " + navigator.appName +
"<br>" );
document.write ( "navigator.appVersion = " + navigator.appVersion +
"<br>" );
document.write ( "navigator.userAgent = " + navigator.userAgent +
"<br>" );
Result :
'window.location' information ( manual ) :
Copy of the javascript code :
document.write ( "location.hash = "
+ location.hash + "<br>" );
document.write ( "location.host = " + location.host + "<br>" );
document.write ( "location.hostname = " + location.hostname +
"<br>" );
document.write ( "location.href = " + location.href + "<br>" );
document.write ( "location.pathname = " + location.pathname +
"<br>" );
document.write ( "location.port = " + location.port + "<br>" );
document.write ( "location.protocol = " + location.protocol +
"<br>" );
document.write ( "location.search = " + location.search + "<br>"
);
Result :
Execute 'location.reload' :
'window.history' information ( manual ) :
Copy of the javascript code :
document.write ( "window.history.length
= " + window.history.length + "<br>" );
document.write ( "window.history[0] = " + window.history[0] +
"<br>" );
document.write ( "window.history[1] = " + window.history[0] +
"<br>" );
document.write ( "window.history[-1] = " + window.history[0] +
"<br>" );
Result :
Execute 'history.back(1)' :
Execute 'history.forward(1)' :
Execute 'history.go(-1)' :
2. Getting 'document' information,
property by property
General 'document' information ( manual ) :
Copy of the javascript code :
document.write ( "document.alinkColor =
" + document.alinkColor + "<br>" );
document.write ( "document.bgColor = " + document.bgColor +
"<br>" );
document.write ( "document.cookie = " + document.cookie + "<br>"
);
document.write ( "document.fgColor = " + document.fgColor +
"<br>" );
document.write ( "document.lastModified = " + document.lastModified +
"<br>" );
document.write ( "document.linkColor = " + document.linkColor +
"<br>" );
document.write ( "document.location = " + document.location +
"<br>" );
document.write ( "document.referrer = " + document.referrer +
"<br>" );
document.write ( "document.title = " + document.title + "<br>"
);
document.write ( "document.vlinkColor = " + document.vlinkColor +
"<br>" );
Result :
'document.links' information ( manual ) :
Copy of the javascript code :
//----- Length information.
document.write ( "document.links.length = " + document.links.length +
"<br>" );
//----- Links range.
document.write ( "document.links [ 0 ==> " + (document.links.length-1) +
" ] :" + "<br>" );
//----- Loop and write all links.
for (var i = 0; i < document.links.length; i++)
document.write ( "link [ " + i + " ] = " +
document.links[i] + "<br>" );
Result :
Form1 definition
'document.Form1' information ( manual ) :
Copy of the javascript code :
document.write ( "Form1.action = "
+ Form1.action + "<br>" );
document.write ( "Form1.elements.count = " + Form1.elements.count +
"<br>" );
document.write ( "Form1.elements.length = " + Form1.elements.length +
"<br>" );
document.write ( "Form1.encoding = " + Form1.encoding + "<br>"
);
document.write ( "Form1.method = " + Form1.method + "<br>" );
document.write ( "Form1.target = " + Form1.target + "<br>" );
document.write ( "Form1.elements[0].name = " + Form1.elements[0].name +
"<br>" );
document.write ( "Form1.name = " + Form1.name + "<br>" );
document.write ( "document.forms[0].name = " + document.forms[0].name +
"<br>" );
document.write ( "<br>");
Result :
'document.Form1.elements' information ( manual ) :
Copy of the javascript code :
document.write ( "Form1.elements.length
= " + Form1.elements.length + "<br>" );
document.write ( "<br>");
document.write ( "Accessing 'Form1.elements' by NUMBER :" +
"<br>" );
document.write ( "Form1.elements[0].name = " + Form1.elements[0].name +
"<br>" );
document.write ( "Form1.elements[0].value = " + Form1.elements[0].value +
"<br>" );
document.write ( "<br>");
document.write ( "Accessing 'Form1.elements' by NAME :" + "<br>"
);
document.write ( "Form1.Button1.name = " + Form1.Button1.name +
"<br>" );
document.write ( "Form1.Button1.value = " + Form1.Button1.value +
"<br>" );
document.write ( "<br>");
Result :
3. Usefull function : ListAllProperties
Usefull function : ListAllProperties
Copy of the javascript code :
function ListAllProperties ( Object ,
ObjectName )
{
var Result = "" ;
for (var i in Object)
{
// Don't show this property, because it
redefines the forms.
if ( ( i == "innerHTML" )
|| ( i == "outerHTML" ) )
Result = ObjectName + "." + i +
" = " + "<i>Not shown ( because it redefines the object
)<i>"
else
Result = ObjectName + "." + i +
" = " + Object[i] ;
document.write ( Result +
"<br>" );
}
}
//----- To use it :
//ListAllProperties ( window.navigator , "navigator" );
4. Getting all 'window' information
'window' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window , "window" );
Result :
'window.navigator' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.navigator , "navigator" );
Result :
'window.location' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.location , "location" );
Result :
'window.history' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.history , "history" );
Result :
'window.frames' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.frames , "frames" );
Result :
5. Getting all 'document' information
'document' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.document , "document" );
Result :
'document.links' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.document.links , "links" );
Result :
Form2 definition
'document.Form2' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.document.Form2 , "Form2" );
Result :
'document.Form2.elements' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.document.Form2.elements , "Form2" );
Result :
'document.Form2.Button1' information ( automatic ) :
Copy of the javascript code :
ListAllProperties ( window.document.Form2.Button1 , "Button1" ) );
Result :
'document.Form2' information ( manual ) :
Copy of the javascript code :
document.write ( "Form2.action = "
+ Form2.action + "<br>" );
document.write ( "Form2.elements.count = " + Form2.elements.count +
"<br>" );
document.write ( "Form2.elements.length = " + Form2.elements.length +
"<br>" );
document.write ( "Form2.encoding = " + Form2.encoding + "<br>"
);
document.write ( "Form2.method = " + Form2.method + "<br>" );
document.write ( "Form2.target = " + Form2.target + "<br>" );
document.write ( "Form2.elements[0].name = " + Form2.elements[0].name +
"<br>" );
document.write ( "Form2.name = " + Form2.name + "<br>" );
document.write ( "document.forms[1].name = " + document.forms[1].name +
"<br>" );
Result :
'document.Form2.elements' information ( manual ) :
Copy of the javascript code :
document.write ( "Form2.elements.length
= " + Form2.elements.length + "<br>");
document.write ( "<br>");
document.write ( "Accessing 'Form2.elements' by NUMBER :" +
"<br>" );
document.write ( "Form2.elements[0].name = " + Form2.elements[0].name +
"<br>");
document.write ( "Form2.elements[0].value = " + Form2.elements[0].value +
"<br>");
document.write ( "<br>");
document.write ( "Accessing 'Form2.elements' by NAME :" + "<br>"
);
document.write ( "Form2.Button1.name = " + Form2.Button1.name +
"<br>" );
document.write ( "Form2.Button1.value = " + Form2.Button1.value +
"<br>" );
document.write ( "<br>");
Result :