Vous êtes sur la page 1sur 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

Vous aimerez peut-être aussi