Examples
Examples
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:
Form Object
Action
<html>
<body>
Output:
Length
<html>
<body>
Output:
Method
<html>
<body>
Output:
The method for sending form-data is: get
Name
<html>
<body>
Output:
The name of the form is: form1
Target
<html>
<body>
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