SlideShare a Scribd company logo
Javascript
Javascript
Window object:
At the very top of the document object hierarchy is the window object. It is the
master container for all content we view in the Web browser. As long as a browser
window is open —even if no document is loaded in the window — the window
object is defined in the current model in memory. The window object is supported
by all browsers. It represent the browsers window. All global JavaScript objects,
functions, and variables automatically become members of the window object.
Global variables are properties of the window object. Global functions are
methods of the window object. Even the document object (of the HTML DOM) is
a property of the window object. In addition to the content part of the window
where documents go, a window’s sphere of influence includes the dimensions of
the window and all of the “stuff” that surrounds the content area. The area where
scrollbars, toolbars, the status bar, and menu bar live is known as a window’s
chrome.
window.document.getElementById("header");
is the same as:
document.getElementById("header");
.
Accessing window properties and methods:
window.propertyName
window.methodName([parameters])
Creating a window
The method that generates a new window is window.open(). This method contains
up to three parameters that define window characteristics, such as the URL of the
document to load, its name for TARGET attribute reference purposes in HTML
tags,and physical appearance (size and chrome contingent).
Example:
Var subWindow = window.open(“define.html”, ”def”
,”HEIGHT=200,WIDTH=300”)
To close the subwindow from a script in the main window, use this reference to
the close() method for that subwindow:
subWindow.close()
Example
Window Properties and Methods:
 window.status property
The status bar at the bottom of the browser window normally displays the URL of
a link when you roll the mouse pointer a top it. Other messages also appear in that
space during document loading, Java applet initialization, and the like. However,
we can use JavaScript to display our own messages in the status bar at times that
may be beneficial to our users. For example, rather than display the URL of a link,
we can display a friendlier, plain-language description of the page at the other end
of the link (or a combination of both). We can assign the window.status property
some other text at any time. To change the status bar text of a link as the cursor
hovers atop the link, we trigger the action with an onMouseOver event handler of
a link object.
<A HREF=”http://google.com” onMouseOver=
“window.status=’Visit the google Home page (google.com)’; return true”>
Netscape</A>
window.alert() method:
This window method generates a dialog box that displays whatever text we pass as a
Parameter . A single OK button (whose label wecannot change)enables the user to
dismiss the alert.
Example:
alert(“This is a JavaScript alert dialog.”)
window.confirm() method
The second style of dialog box presents two buttons (Cancel and OK in most ver-
sions on most platforms) and is called a confirm dialog box . More importantly, this
is one of those methods that returns a value: true if the user clicks OK, false if the
user clicks Cancel. We can use this dialog box and its returned value as a way to
have a user make a decision about how a script progresses.
Example:
if (confirm(“Are you sure you want to start over?”)) {
location.href = “index.html”
}
window.prompt() method
The final dialog box of the window object, the prompt dialog box ,displays a
message that we set and provides a text field for the user to enter a response. Two
buttons, Cancel and OK, enable the user to dismiss the dialog box with two
opposite expectations: canceling the entire operation or accepting the input typed
into the dialog box.
Example:
var answer = prompt(“What is your name?”,””)
if (answer) {
alert(“Hello, “ + answer + “!”)
}
 Window size properties
Three different properties can be used to determine the size of the browser
window (the browser viewport, NOT including toolbars and scrollbars).
For Internet Explorer, Chrome, Firefox, Opera, and Safari:
window.innerHeight - the inner height of the browser window
window.innerWidth - the inner width of the browser window
For Internet Explorer 8, 7, 6, 5:
document.documentElement.clientHeight
document.documentElement.clientWidth
or
document.body.clientHeight
document.body.clientWidth
Example:
var
w=window.innerWidth||document.documentElement.clientWidth
|| document.body.clientWidth;
var h=window.innerHeight||
document.documentElement.clientHeight||
document.body.clientHeight;
Other browser methods:
window.moveTo() -move the current window
window.resizeTo() -resize the current window
onLoad event handler
The window object reacts to several system and user events, but the one we will
probably use most often is the event that fires as soon as everything in a page fin-
ishes loading. This event waits for images, Java applets, and data files for plug-ins
to download fully to the browser. All window event handlers are placed inside the
<BODY> tag. Even though we will come to associate the <BODY> tag’s
attributes with the document object’s properties, it is the window object’s event
handlers that go inside the tag.
The Location Object
This object represents the URL loaded into the window. This differs from the
document object because the document is the real content; the location is simply
the URL.
Setting the location.href property is the primary way our scripts navigate to
other pages:
location.href = “http://www.ibm.com”
The History Object
Another object that doesn’t have a physical presence on the page is the history
object. Each window maintains a list of recent pages that the browser has
visited.While the history object’s list contains the URLs of recently visited
pages, those URLs are not generally accessible by script due to privacy and
security limits imposed by browsers. But methods of the history object allow
for navigating backward and forward through the history relative to the
currently loaded page.
The Document Object
The document object holds the real content of the page. Proper ties and
methods of the document object generally affect the look and content of the
document that occupies the window.
[window.]document.propertyName
[window.]document.methodName([parameters])
The window reference is optional when the script is accessing the document
object that contains the script.
Javascript
Document Object:
The Document object provides access to page elements such as anchors, form
fields, and links, as well as page properties such as background and text color.
The structure of this object varies considerably from browser to browser, and
from version to version. Each HTML document loaded into a browser window
becomes a Document object. The Document object provides access to all HTML
elements in a page, from within a script.
Click here to view example
Javascript
Javascript
Javascript
Accessing Document Elements by Position:
For example, if we have a document like below:
<html >
<head>
<title>Simple Form</title>
</head>
<body>
<form action="#“ >
<input type="text" />
</form>
<br /><br />
<form action="#“ >
<input type="text" />
<br />
<input type="text" />
</form>
</body>
</html>
•we can access the first <form>tag using
window.document.forms[0]
•To access the second <form>tag we would use
window.document.forms[1]
The forms[] collection also contains an elements[] collection. This contains the
various form fields like text fields, buttons, pull-downs, and so on. Following the
basic containment concept to reach the first form element in the first form of the
document, we would use window.document.forms[0].elements[0].
Accessing Document Elements by Name:
The basic way to attach a unique identifier to an (X)HTML element is by using the
id attribute. The id attribute is associated with nearly every (X)HTML
element.
For example, to name a particular enclosed embolded piece of text :
<b id=“textbold“>This is very important.</b>
Example:
<form name="myForm" id="myForm“ >
<input type="text" name="userName" id="userName" />
</form>
And then to access the form from JavaScript, we would use either
window.document.myForm
or simply
document.myForm
Or
document.getElementById(“myForm”)
Accessing Objects Using Associate Arrays:
Example:
<form name="myForm2" id="myForm2" method="get" action="#">
<input name="user" type="text" value="" />
</form>
We can access the form as document.forms["myForm2"] or even use the
elements[] array of the Form object to access the field as
document.forms["myForm2"].elements["user"].
Event Handlers:
The code is executed if and when the given event occurs at the part of the
document to which it is associated. Common events include Click, MouseOver,
and MouseOut, which occur when the user clicks, places the mouse over, or
moves the mouse away from a portion of the document, respectively. These events
are commonly associated with form buttons, form fields, images, and links, and
are used for tasks like form field validation and rollover buttons.
Example:
<form >
<input type="button" value="Click me" onclick="alert('That
tickles!');" />
</form>
Click here to view example

More Related Content

PPTX
Internet and Web Technology (CLASS-6) [BOM]
PPTX
Java script Advance
PPTX
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
PPTX
Internet and Web Technology (CLASS-5) [HTML DOM]
PDF
PDF
22 j query1
PPTX
Presentation
PDF
Intro to jQuery
Internet and Web Technology (CLASS-6) [BOM]
Java script Advance
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-5) [HTML DOM]
22 j query1
Presentation
Intro to jQuery

What's hot (20)

PPTX
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
PPTX
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
PDF
Intro to Javascript and jQuery
DOCX
Managing states
PDF
Class Intro / HTML Basics
PDF
1 ppt-ajax with-j_query
PDF
Documentation For Tab Setup
PPTX
Globodox overview
PDF
Javascript projects Course
PPTX
2.java script dom
PPTX
YL form tag with checkbox
PDF
Getting Started with DOM
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
PDF
Introduction to js (cnt.)
PDF
Web development resources brackets
PPT
Session vii(java scriptbasics)
PPTX
Functionality
PPTX
Xsd restrictions, xsl elements, dhtml
PDF
ASP.Net, move data to and from a SQL Server Database
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Intro to Javascript and jQuery
Managing states
Class Intro / HTML Basics
1 ppt-ajax with-j_query
Documentation For Tab Setup
Globodox overview
Javascript projects Course
2.java script dom
YL form tag with checkbox
Getting Started with DOM
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
Introduction to js (cnt.)
Web development resources brackets
Session vii(java scriptbasics)
Functionality
Xsd restrictions, xsl elements, dhtml
ASP.Net, move data to and from a SQL Server Database
Ad

Viewers also liked (20)

PPTX
Javascript Objects and Functions
PPTX
More Little Wonders of C#/.NET
PDF
How We Used Analytics to Fuel Our Growth
PPTX
DOC
Zresume Work Exp
PPT
Crawl, Walk, Run to Social Media Success
PDF
Globalization
PPTX
Endocrine system
PPTX
АСУ ЛТЦ, Логистический транспортный центр для АНО СОЧИ 2014, ТрансСистемоТехника
PPTX
Valores Morales
PDF
1996 ATLANTA CENTENNIAL OLYMPIC LOOK OF THE GAMES LOGO DESIGNS
PPT
Vestas QPEX Plan
DOCX
Example-Project Brief
PPT
PPT
Web design Tools
PDF
Повышение эффективности работы каландровой линии
PDF
Оптимизация рабочего времени работников обслуживания АПС
PPTX
Acute renal failure in children
Javascript Objects and Functions
More Little Wonders of C#/.NET
How We Used Analytics to Fuel Our Growth
Zresume Work Exp
Crawl, Walk, Run to Social Media Success
Globalization
Endocrine system
АСУ ЛТЦ, Логистический транспортный центр для АНО СОЧИ 2014, ТрансСистемоТехника
Valores Morales
1996 ATLANTA CENTENNIAL OLYMPIC LOOK OF THE GAMES LOGO DESIGNS
Vestas QPEX Plan
Example-Project Brief
Web design Tools
Повышение эффективности работы каландровой линии
Оптимизация рабочего времени работников обслуживания АПС
Acute renal failure in children
Ad

Similar to Javascript (20)

PPT
13488117.ppt
PPT
13488117.ppt
PDF
Java script browser objects 1
 
PPT
Learn javascript easy steps
PPT
Easy javascript
PPT
Applied component i unit 2
PPT
Week8
PPTX
JavaScript
PPTX
12. session 12 java script objects
PDF
Intro to JavaScript
PPTX
Learn Javascript Basics
PPTX
Window object
PDF
Intro to JavaScript
PPTX
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
PPTX
Art of Javascript
PPT
The Theory Of The Dom
PDF
INTRODUCTION TO CLIENT SIDE PROGRAMMING
PPTX
Learning About JavaScript (…and its little buddy, JQuery!)
PPTX
javaScript and jQuery
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
13488117.ppt
13488117.ppt
Java script browser objects 1
 
Learn javascript easy steps
Easy javascript
Applied component i unit 2
Week8
JavaScript
12. session 12 java script objects
Intro to JavaScript
Learn Javascript Basics
Window object
Intro to JavaScript
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Art of Javascript
The Theory Of The Dom
INTRODUCTION TO CLIENT SIDE PROGRAMMING
Learning About JavaScript (…and its little buddy, JQuery!)
javaScript and jQuery
JavaScript - Chapter 13 - Browser Object Model(BOM)

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cell Types and Its function , kingdom of life
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Classroom Observation Tools for Teachers
PDF
Basic Mud Logging Guide for educational purpose
PDF
Pre independence Education in Inndia.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Lesson notes of climatology university.
TR - Agricultural Crops Production NC III.pdf
Cell Types and Its function , kingdom of life
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Computing-Curriculum for Schools in Ghana
Microbial diseases, their pathogenesis and prophylaxis
Microbial disease of the cardiovascular and lymphatic systems
Sports Quiz easy sports quiz sports quiz
Classroom Observation Tools for Teachers
Basic Mud Logging Guide for educational purpose
Pre independence Education in Inndia.pdf
01-Introduction-to-Information-Management.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Abdominal Access Techniques with Prof. Dr. R K Mishra
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharma ospi slides which help in ospi learning
Anesthesia in Laparoscopic Surgery in India
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.

Javascript

  • 3. Window object: At the very top of the document object hierarchy is the window object. It is the master container for all content we view in the Web browser. As long as a browser window is open —even if no document is loaded in the window — the window object is defined in the current model in memory. The window object is supported by all browsers. It represent the browsers window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object. Global functions are methods of the window object. Even the document object (of the HTML DOM) is a property of the window object. In addition to the content part of the window where documents go, a window’s sphere of influence includes the dimensions of the window and all of the “stuff” that surrounds the content area. The area where scrollbars, toolbars, the status bar, and menu bar live is known as a window’s chrome. window.document.getElementById("header"); is the same as: document.getElementById("header"); .
  • 4. Accessing window properties and methods: window.propertyName window.methodName([parameters]) Creating a window The method that generates a new window is window.open(). This method contains up to three parameters that define window characteristics, such as the URL of the document to load, its name for TARGET attribute reference purposes in HTML tags,and physical appearance (size and chrome contingent). Example: Var subWindow = window.open(“define.html”, ”def” ,”HEIGHT=200,WIDTH=300”) To close the subwindow from a script in the main window, use this reference to the close() method for that subwindow: subWindow.close() Example
  • 5. Window Properties and Methods:  window.status property The status bar at the bottom of the browser window normally displays the URL of a link when you roll the mouse pointer a top it. Other messages also appear in that space during document loading, Java applet initialization, and the like. However, we can use JavaScript to display our own messages in the status bar at times that may be beneficial to our users. For example, rather than display the URL of a link, we can display a friendlier, plain-language description of the page at the other end of the link (or a combination of both). We can assign the window.status property some other text at any time. To change the status bar text of a link as the cursor hovers atop the link, we trigger the action with an onMouseOver event handler of a link object. <A HREF=”http://google.com” onMouseOver= “window.status=’Visit the google Home page (google.com)’; return true”> Netscape</A>
  • 6. window.alert() method: This window method generates a dialog box that displays whatever text we pass as a Parameter . A single OK button (whose label wecannot change)enables the user to dismiss the alert. Example: alert(“This is a JavaScript alert dialog.”) window.confirm() method The second style of dialog box presents two buttons (Cancel and OK in most ver- sions on most platforms) and is called a confirm dialog box . More importantly, this is one of those methods that returns a value: true if the user clicks OK, false if the user clicks Cancel. We can use this dialog box and its returned value as a way to have a user make a decision about how a script progresses. Example: if (confirm(“Are you sure you want to start over?”)) { location.href = “index.html” }
  • 7. window.prompt() method The final dialog box of the window object, the prompt dialog box ,displays a message that we set and provides a text field for the user to enter a response. Two buttons, Cancel and OK, enable the user to dismiss the dialog box with two opposite expectations: canceling the entire operation or accepting the input typed into the dialog box. Example: var answer = prompt(“What is your name?”,””) if (answer) { alert(“Hello, “ + answer + “!”) }  Window size properties Three different properties can be used to determine the size of the browser window (the browser viewport, NOT including toolbars and scrollbars). For Internet Explorer, Chrome, Firefox, Opera, and Safari: window.innerHeight - the inner height of the browser window window.innerWidth - the inner width of the browser window
  • 8. For Internet Explorer 8, 7, 6, 5: document.documentElement.clientHeight document.documentElement.clientWidth or document.body.clientHeight document.body.clientWidth Example: var w=window.innerWidth||document.documentElement.clientWidth || document.body.clientWidth; var h=window.innerHeight|| document.documentElement.clientHeight|| document.body.clientHeight;
  • 9. Other browser methods: window.moveTo() -move the current window window.resizeTo() -resize the current window onLoad event handler The window object reacts to several system and user events, but the one we will probably use most often is the event that fires as soon as everything in a page fin- ishes loading. This event waits for images, Java applets, and data files for plug-ins to download fully to the browser. All window event handlers are placed inside the <BODY> tag. Even though we will come to associate the <BODY> tag’s attributes with the document object’s properties, it is the window object’s event handlers that go inside the tag. The Location Object This object represents the URL loaded into the window. This differs from the document object because the document is the real content; the location is simply the URL. Setting the location.href property is the primary way our scripts navigate to other pages: location.href = “http://www.ibm.com”
  • 10. The History Object Another object that doesn’t have a physical presence on the page is the history object. Each window maintains a list of recent pages that the browser has visited.While the history object’s list contains the URLs of recently visited pages, those URLs are not generally accessible by script due to privacy and security limits imposed by browsers. But methods of the history object allow for navigating backward and forward through the history relative to the currently loaded page. The Document Object The document object holds the real content of the page. Proper ties and methods of the document object generally affect the look and content of the document that occupies the window.
  • 11. [window.]document.propertyName [window.]document.methodName([parameters]) The window reference is optional when the script is accessing the document object that contains the script.
  • 13. Document Object: The Document object provides access to page elements such as anchors, form fields, and links, as well as page properties such as background and text color. The structure of this object varies considerably from browser to browser, and from version to version. Each HTML document loaded into a browser window becomes a Document object. The Document object provides access to all HTML elements in a page, from within a script. Click here to view example
  • 17. Accessing Document Elements by Position: For example, if we have a document like below: <html > <head> <title>Simple Form</title> </head> <body> <form action="#“ > <input type="text" /> </form> <br /><br /> <form action="#“ > <input type="text" /> <br /> <input type="text" /> </form> </body> </html>
  • 18. •we can access the first <form>tag using window.document.forms[0] •To access the second <form>tag we would use window.document.forms[1] The forms[] collection also contains an elements[] collection. This contains the various form fields like text fields, buttons, pull-downs, and so on. Following the basic containment concept to reach the first form element in the first form of the document, we would use window.document.forms[0].elements[0]. Accessing Document Elements by Name: The basic way to attach a unique identifier to an (X)HTML element is by using the id attribute. The id attribute is associated with nearly every (X)HTML element. For example, to name a particular enclosed embolded piece of text : <b id=“textbold“>This is very important.</b>
  • 19. Example: <form name="myForm" id="myForm“ > <input type="text" name="userName" id="userName" /> </form> And then to access the form from JavaScript, we would use either window.document.myForm or simply document.myForm Or document.getElementById(“myForm”) Accessing Objects Using Associate Arrays: Example: <form name="myForm2" id="myForm2" method="get" action="#"> <input name="user" type="text" value="" /> </form> We can access the form as document.forms["myForm2"] or even use the elements[] array of the Form object to access the field as document.forms["myForm2"].elements["user"].
  • 20. Event Handlers: The code is executed if and when the given event occurs at the part of the document to which it is associated. Common events include Click, MouseOver, and MouseOut, which occur when the user clicks, places the mouse over, or moves the mouse away from a portion of the document, respectively. These events are commonly associated with form buttons, form fields, images, and links, and are used for tasks like form field validation and rollover buttons. Example: <form > <input type="button" value="Click me" onclick="alert('That tickles!');" /> </form> Click here to view example