0% found this document useful (0 votes)
59 views

Examples

The document provides examples of using various properties and methods of the Window, Document, Form, Navigator and Screen objects in JavaScript to retrieve information about the browser window, document, forms, browser and screen. This includes getting the number of frames or URLs in history, protocol, title, cookies, domain, and more. It also demonstrates getting properties like the app name, version and platform of the Navigator as well as dimensions and color depth of the Screen.

Uploaded by

Sathish
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Examples

The document provides examples of using various properties and methods of the Window, Document, Form, Navigator and Screen objects in JavaScript to retrieve information about the browser window, document, forms, browser and screen. This includes getting the number of frames or URLs in history, protocol, title, cookies, domain, and more. It also demonstrates getting properties like the app name, version and platform of the Navigator as well as dimensions and color depth of the Screen.

Uploaded by

Sathish
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

Window Object

Frames

<html>
<body>
<iframe src="http://microsoft.com"></iframe>
<iframe src="http://google.com"></iframe>
<iframe src="http://youtube.com"></iframe>
<script type="text/javascript">
for (var i=0; i<frames.length; i++)
 {
  frames[i].location="http://piratestn.webs.com"
 }
</script>
</body>
</html>

History

<html>
<body>
<script type="text/javascript">
document.write("Number of URLs in history list: " + history.length);
</script>
</body>
</html>

Output
Number of URLs in history list: 2

Location

<html>
<body>
<script type="text/javascript">
document.write(location.protocol);
</script>
</body>
</html>
Output:
http:

Name

<html>
<head>
<script type="text/javascript">
var myWindow;
function openWin()
{
myWindow=window.open('','MsgWindow','width=200,height=100');
myWindow.document.write("This window's name is: " + myWindow.name);
}
</script>
</head>
<body>
<input type="button" value="Open 'myWindow' " onclick="openWin()" />
</body>
</html>

Navigator

<html>
<body>
<script type="text/javascript">
document.write("Version info: " + navigator.appVersion);
</script>
</body>
</html>

Output:
Version info: 5.0 (Windows; en-US)

Screen

<html>
<body>
<script type="text/javascript">
document.write("Available Width: " + screen.availWidth);
</script>
</body>
</html>

Output:
Available Width: 1366

Self

<html>
<head>
<script type="text/javascript">
function check()
{
if (window.top!=window.self)
{
document.write("This window is not the topmost window! Am I in a frame?")
}
else
{
document.write("This window is the topmost window!")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="Check window" />
</body>
</html>

Status

<html>
<body>
<script type="text/javascript">
window.status="Some text in the status bar!!";
</script>
</body>
</html>
Document Object

Cookie

<html>
<body>
Cookies associated with this document:
<script type="text/javascript">
document.write(document.cookie);
</script>
</body>
</html>

Output:
Cookies associated with this document:
__utma=119627022.52052259.1296985780.1297145346.1297184070.5;
__utmz=119627022.1297184070.5.7.utmcsr=google|utmccn=(organic)|utmcmd=organic|
utmctr=w3schools%20javascript;
ASPSESSIONIDSCDQDCBQ=FOLHCFKADIEAOLOFKOBIDKOH;
__utmb=119627022.37.10.1297184070; __utmc=119627022

Domain

<html>
<body>
The domain name for the server that loaded this document:
<script type="text/javascript">
document.write(document.domain);
</script>
</body>
</html>

Output:
The domain name for the server that loaded this document is www.piratestn.webs.com
Last Modified

<html>
<body>
<script type="text/javascript">
document.write(document.lastModified);
</script>
</body>
</html>

Output:
01/14/2011 20:22:35

Title

<html>
<head>
<title>My title</title>
</head>
<body>
The title of the document is:
<script type="text/javascript">
document.write(document.title);
</script>
</body>
</html>

Output:
The title of the document is: My title

URL

<html>
<body>
The full URL of this document is:
<script type="text/javascript">
document.write(document.URL);
</script>
</body>
</html>
Output:

The full URL of this document is: http://www.w3schools.com/jsref/tryit_view.asp?


filename=tryjsref_doc_url

Form Object

Action

<html>
<body>

<form id="frm1" action="form_action.asp">


First name: <input type="text" name="fname" value="Donald" /><br />
Last name: <input type="text" name="lname" value="Duck" /><br />
<input type="submit" value="Submit" />
</form>

The value of the action attribute is:


<script type="text/javascript">
document.write(document.getElementById("frm1").action);
</script>
</body>
</html>

Output:

The value of the action attribute is: http://www.w3schools.com/jsref/form_action.asp

Length

<html>
<body>

<form id="frm1" action="form_action.asp">


First name: <input type="text" name="fname" value="Donald" /><br />
Last name: <input type="text" name="lname" value="Duck" /><br />
<input type="submit" value="Submit" />
</form>
The number of elements in "frm1" are:
<script type="text/javascript">
document.write(document.getElementById("frm1").length);
</script>
</body>
</html>

Output:

The number of elements in "frm1" are: 3

Method

<html>
<body>

<form id="frm1" action="form_action.asp" method="get">


First name: <input type="text" name="fname" value="Donald" /><br />
Last name: <input type="text" name="lname" value="Duck" /><br />
<input type="submit" value="Submit" />
</form>

The method for sending form-data is:


<script type="text/javascript">
document.write(document.getElementById("frm1").method);
</script>
</body>
</html>

Output:
The method for sending form-data is: get

Name

<html>
<body>

<form id="frm1" name="form1">


First name: <input type="text" name="fname" value="Donald" /><br />
Last name: <input type="text" name="lname" value="Duck" /><br />
</form>

The name of the form is:


<script type="text/javascript">
document.write(document.getElementById("frm1").name);
</script>
</body>
</html>

Output:
The name of the form is: form1

Target

<html>
<body>

<form id="frm1" action="form_action.asp" target="_blank">


First name: <input type="text" name="fname" value="Donald" /><br />
Last name: <input type="text" name="lname" value="Duck" /><br />
<input type="submit" value="Submit" />
</form>

The value of the target attribute is:


<script type="text/javascript">
document.write(document.getElementById("frm1").target);
</script>
</body>
</html>

Output:
The value of the target attribute is: _blank

Navigator Object

Appcode name

<html>
<body>
<script type="text/javascript">
document.write("CodeName: " + navigator.appCodeName);
</script>

</body>
</html>

Output:
CodeName: Explorer

AppName

<html>
<body>

<script type="text/javascript">
document.write("Name: " + navigator.appName);
</script>

</body>
</html>

Output:
Name: Firefox

Appversion

<html>
<body>

<script type="text/javascript">
document.write("Version info: " + navigator.appVersion);
</script>

</body>
</html>

Output:
Version info: 5.0 (Windows; en-US)
Cookie Enabled

<html>
<body>

<script type="text/javascript">
document.write("Cookies enabled: " + navigator.cookieEnabled);
</script>

</body>
</html>

Output:
Cookies enabled: true

Platform

<html>
<body>

<script type="text/javascript">
document.write("Platform: " + navigator.platform);
</script>

</body>
</html>

Output:
Platform: Win32 // windows 32 bit

Screen Object

AvailHeight

<html>
<body>
<script type="text/javascript">
document.write("Available Height: " + screen.availHeight);
</script>
</body>
</html>

Output:
Available Height: 738

AvailWidth

<html>
<body>
<script type="text/javascript">
document.write("Available Width: " + screen.availWidth);
</script>
</body>
</html>

Output:
Available Width: 1366

Color Depth

<html>
<body>
<script type="text/javascript">
document.write("Color Depth: " + screen.colorDepth);
</script>
</body>
</html>

Output:
Color Depth: 24

Height

<html>
<body>
<script type="text/javascript">
document.write("Total Height: " + screen.height);
</script>
</body>
</html>
Output:
Total Height: 768

Width

<html>
<body>
<script type="text/javascript">
document.write("Total Width: " + screen.width);
</script>
</body>
</html>

Output:
Total Width: 1366

You might also like