SlideShare a Scribd company logo
1 of 92
COURSE 09
JAVASCRIPT
lect. eng. Rajmond JÁNÓ, PhD
rajmond.jano@ael.utcl
uj.ro
fb.com/janorajmond
C09 – JAVASCRIPT
• HTML DOM
• HTML BOM
• Popup boxes
• Timing events
• Cookies
• Local storage
• Examples
JAVASCRIPT HTML DOM
• With the HTML DOM, JavaScript can access and
change all the elements of an HTML document
• When a web page is loaded, the browser
creates a Document Object Model of the page
JAVASCRIPT HTML DOM
• The HTML DOM model is constructed as a tree
of Objects
JAVASCRIPT HTML DOM
With the object model, JavaScript gets all the power
it needs to create dynamic HTML.
JavaScript can:
• Change all the HTML elements in the page
• Change all the HTML attributes in the page
• Change all the CSS styles in the page
• Remove existing HTML elements and attributes
• Add new HTML elements and attributes
• React to all existing HTML events in the page
• Create new HTML events in the page
JAVASCRIPT HTML DOM
• The DOM is a W3C (World Wide Web Consortium)
standard
• The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform
and language-neutral interface that allows programs and
scripts to dynamically access and update the content,
structure, and style of a document."
• The W3C DOM standard is separated into 3 different
parts:
• Core DOM - standard model for all document types
• XML DOM - standard model for XML documents
• HTML DOM - standard model for HTML documents
JAVASCRIPT HTML DOM
The HTML DOM is a standard object model and
programming interface for HTML. It defines:
• The HTML elements as objects
• The properties of all HTML elements
• The methods to access all HTML elements
• The events for all HTML elements
In other words: The HTML DOM is a standard for
how to get, change, add, or delete HTML
elements.
JAVASCRIPT HTML DOM
METHODS
• HTML DOM methods are actions you can
perform (on HTML Elements)
• HTML DOM properties are values (of HTML
Elements) that you can set or change
JAVASCRIPT HTML DOM
METHODS
The DOM Programming Interface
• The HTML DOM can be accessed with JavaScript (and with
other programming languages)
• In the DOM, all HTML elements are defined as objects
• The programming interface is the properties and methods
of each object
• A property is a value that you can get or set (like changing
the content of an HTML element)
• A method is an action you can do (like add or deleting an
HTML element)
JAVASCRIPT HTML DOM
DOCUMENT
• The HTML DOM document object is the owner
of all other objects in your web page
• The document object represents your web
page
• If you want to access any element in an HTML
page, you always start with accessing the
document object
JAVASCRIPT HTML DOM
ELEMENTS
• Often, with JavaScript, you want to manipulate
HTML elements
• To do so, you have to find the elements first. There
are several ways to do this:
• Finding HTML elements by id
• Finding HTML elements by tag name
• Finding HTML elements by class name
• Finding HTML elements by CSS selectors
• Finding HTML elements by HTML object collections
JAVASCRIPT HTML DOM
ELEMENTS
• The easiest way to find an HTML element in
the DOM, is by using the element id
• If the element is found, the method will return
the element as an object (in myElement)
• If the element is not found, myElement will
contain null
JAVASCRIPT HTML DOM
ELEMENTS
• Finding HTML Elements by Tag Name
JAVASCRIPT HTML DOM
ELEMENTS
• Finding HTML Elements by Class Name
• If you want to find all HTML elements with the same
class name, use getElementsByClassName()
JAVASCRIPT HTML DOM
ELEMENTS
• Finding HTML Elements by CSS Selectors
• If you want to find all HTML elements that match a
specified CSS selector (id, class names, types,
attributes, values of attributes, etc), use the
querySelectorAll() method
JAVASCRIPT HTML DOM
ELEMENTS
• Finding HTML Elements by HTML Object Collections
• The following HTML objects (and object collections) are
also accessible:
• document.anchors
• document.body
• document.documentElement
• document.embeds
• document.forms
• document.head
• document.images
• document.links
• document.scripts
• document.title
CHANGING THE HTML OUTPUT
STREAM
• JavaScript can create dynamic HTML content
• In JavaScript, document.write() can be used
to write directly to the HTML output stream
Never use document.write()after the document is
loaded.
It will overwrite the document content.
CHANGING HTML CONTENT
• The easiest way to modify the content of an
HTML element is by using the innerHTML
property.
• To change the content of an HTML element,
use this syntax
CHANGING THE VALUE OF AN
ATTRIBUTE
• To change the value of an HTML attribute, use
this syntax
JAVASCRIPT HTML DOM –
CHANGING CSS
• The HTML DOM allows JavaScript to change the
style of HTML elements
• Changing HTML Style
• To change the style of an HTML element, use this
syntax
JAVASCRIPT HTML DOM –
CHANGING CSS
• The HTML DOM also allows JavaScript to
manipulate the CSS classes of HTML elements
• Setting classes
• Adding classes
• Removing classes
• Toggling classes
JAVASCRIPT HTML DOM EVENTS
• HTML DOM allows JavaScript to react to HTML
events
• A JavaScript can be executed when an event occurs,
like when a user clicks on an HTML element
• Examples of HTML events:
• When a user clicks the mouse
• When a web page has loaded
• When an image has been loaded
• When the mouse moves over an element
• When an input field is changed
• When an HTML form is submitted
• When a user strokes a key
ADDING EVENTS
There are three ways to add events to HTML
elements
• HTML event attributes
• Assigning events using the HTML DOM
• Adding an event listener using the
addEventListener() method
Please avoid this method, use the other
two!
EVENT BUBBLING OR EVENT
CAPTURING
• The same HTML element can have multiple
events and HTML elements embedded into
each other can have different functions defined
for the same event
• So in what order to these events get executed,
then?
EVENT BUBBLING OR EVENT
CAPTURING
There are two ways of event propagation in the HTML DOM,
bubbling and capturing
• Event propagation is a way of defining the element order when an
event occurs
• If you have a <p> element inside a <div> element, and the user clicks on
the <p> element, which element's "click" event should be handled first?
• In bubbling the inner most element's event is handled first and
then the outer
• The <p> element's click event is handled first, then the <div> element's
click event
• In capturing the outer most element's event is handled first and
then the inner
• The <div> element's click event will be handled first, then the <p>
element's click event
EVENT BUBBLING OR EVENT
CAPTURING
With the addEventListener() method you can
specify the propagation type by using the
useCapture parameter
JAVASCRIPT HTML DOM
NAVIGATION
With the HTML DOM, you can navigate the node tree
using node relationships.
DOM Nodes
According to the W3C HTML DOM standard,
everything in an HTML document is a node:
• The entire document is a document node
• Every HTML element is an element node
• The text inside HTML elements are text nodes
• All comments are comment nodes
JAVASCRIPT HTML DOM
NAVIGATION
• With the HTML DOM, all nodes in the node tree
can be accessed by JavaScript
• New nodes can be created, and all nodes can
be modified or deleted
NODE RELATIONSHIPS
• The nodes in the node tree have a hierarchical
relationship to each other
• The terms parent, child, and sibling are used to
describe the relationships
• In a node tree, the top node is called the root (or root
node)
• Every node has exactly one parent, except the root
(which has no parent)
• A node can have a number of children
• Siblings (brothers or sisters) are nodes with the same
parent
NODE RELATIONSHIPS
From the HTML above you can read:
<html> is the root node
<html> has no parents
<html> is the parent of <head> and <body>
<head> is the first child of <html>
<body> is the last child of <html>
and:
<head> has one child: <title>
<title> has one child (a text node): "DOM Tutorial"
<body> has two children: <h1> and <p>
<h1> has one child: "DOM Lesson one"
<p> has one child: "Hello world!"
<h1> and <p> are siblings
NAVIGATING BETWEEN NODES
• You can use the following node properties to
navigate between nodes with JavaScript:
• parentNode
• childNodes[nodenumber]
• firstChild
• lastChild
• nextSibling
• previousSibling
CHILD NODES AND NODE
VALUES
• A common error in DOM processing is to expect an element node
to contain text
• The element node <title> (in the example above) does not contain
text
• It contains a text node with the value "DOM Tutorial"
• The value of the text node can be accessed by the node's
innerHTML property:
• Accessing the innerHTML property is the same as accessing the
nodeValue of the first child:
• Accessing the first child can also be done like this:
DOM ROOT NODES
There are two special properties that allow
access to the full document:
• document.body – The body of the document
• document.documentElement – The full document
CREATING NEW HTML ELEMENTS
(NODES)
• To add a new element to the HTML DOM, you
must create the element (element node) first,
and then append it to an existing element
THE BROWSER OBJECT MODEL
(BOM)
• The Browser Object Model (BOM) allows
JavaScript to "talk to" the browser
• There are no official standards for the BOM
• Since modern browsers have implemented
(almost) the same methods and properties for
JavaScript interactivity, it is often referred to,
as methods and properties of the BOM
THE WINDOW OBJECT
• The window object is supported by all browsers. It
represents the browser's 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
WINDOW SIZE AND METHODS
• Two properties can be used to determine the
size of the browser window
• Both properties return the sizes in pixels:
• window.innerHeight – the inner height of the
browser window (in pixels)
• window.innerWidth – the inner width of the
browser window (in pixels)
The browser window (the browser
viewport) is NOT including toolbars
and scrollbars.
WINDOW SIZE AND METHODS
• Some other window methods:
• window.open() – open a new window
• window.close() – close the current
window
• window.moveTo() – move the current
window
• window.resizeTo() – resize the current
window
JAVASCRIPT WINDOW SCREEN
• The window.screen object contains information about the
user's screen
• The window.screen object can be written without the
window prefix
• Properties:
• screen.width – returns the width of the visitor's screen in pixels
• screen.height – returns the height of the visitor's screen in pixels
• screen.availWidth – returns the width of the visitor's screen, in
pixels, minus interface features like the Windows Taskbar
• screen.availHeight – returns the height of the visitor's screen, in
pixels, minus interface features like the Windows Taskbar
• screen.colorDepth – returns the number of bits used to display
one color
JAVASCRIPT WINDOW LOCATION
• The window.location object can be used to get the current
page address (URL) and to redirect the browser to a new
page
• The window.location object can be written without the
window prefix
• Some examples:
• window.location.href – returns the href (URL) of the current
page
• window.location.hostname – returns the domain name of the
web host
• window.location.pathname – returns the path and filename of
the current page
• window.location.protocol – returns the web protocol used
(http: or https:)
JAVASCRIPT WINDOW HISTORY
• The window.history object contains the browsers
history
• The window.history object can be written without
the window prefix
• To protect the privacy of the users, there are
limitations to how JavaScript can access this object
• Some methods:
• history.back() – same as clicking back in the browser
• history.forward() – same as clicking forward in the
browser
JAVASCRIPT WINDOW
NAVIGATOR
• The window.navigator object contains
information about the visitor's browser
• The window.navigator object can be written
without the window prefix
JAVASCRIPT WINDOW
NAVIGATOR
• Browser Cookies
• The cookieEnabled property returns true if cookies
are enabled, otherwise false
• Browser Application Name
• The appName property returns the application name
of the browser
• "Netscape" is the application name for both IE11,
Chrome, Firefox, and Safari
JAVASCRIPT WINDOW
NAVIGATOR
• Browser Application Code Name
• The appCodeName property returns the application
code name of the browser
• "Mozilla" is the application code name for both
Chrome, Firefox, IE, Safari, and Opera
• The Browser Engine
• The product property returns the product name of
the browser engine
• Do not rely on this, most browsers return "Gecko" as
product name
JAVASCRIPT WINDOW
NAVIGATOR
• The Browser Version
• The appVersion property returns version
information about the browser
• The Browser Agent
• The userAgent property returns the user-agent
header sent by the browser to the server
JAVASCRIPT WINDOW
NAVIGATOR
• The information from the navigator object can
often be misleading, and should not be used
to detect browser versions because:
• Different browsers can use the same name
• The navigator data can be changed by the browser
owner
• Some browsers misidentify themselves to bypass
site tests
• Browsers cannot report new operating systems,
released later than the browser
JAVASCRIPT WINDOW
NAVIGATOR
• The Browser Platform
• The platform property returns the browser platform
(operating system)
• The Browser Language
• The language property returns the browser's
language
• Is The Browser Online?
• The onLine property returns true if the browser is
online
• Is Java Enabled?
JAVASCRIPT POPUP BOXES
Alert Box
• An alert box is often used if you want to make
sure information comes through to the user
• When an alert box pops up, the user will have
to click "OK" to proceed
JAVASCRIPT POPUP BOXES
Confirm Box
• A confirm box is often used if you want the
user to verify or accept something
• When a confirm box pops up, the user will
have to click either "OK" or "Cancel" to
proceed.
• If the user clicks "OK", the box returns true. If the
user clicks "Cancel", the box returns false
JAVASCRIPT POPUP BOXES
Confirm Box
JAVASCRIPT POPUP BOXES
Prompt Box
• A prompt box is often used if you want the
user to input a value before entering a page
• When a prompt box pops up, the user will have
to click either "OK" or "Cancel" to proceed after
entering an input value
• If the user clicks "OK" the box returns the input
value. If the user clicks "Cancel" the box returns null
JAVASCRIPT POPUP BOXES
Prompt Box
JAVASCRIPT TIMING EVENTS
• The window object allows execution of code at
specified time intervals
• These time intervals are called timing events
• The two key methods to use with JavaScript are:
• setTimeout(function, milliseconds)
• Executes a function, after waiting a specified number of
milliseconds
• setInterval(function, milliseconds)
• Same as setTimeout(), but repeats the execution of the
function continuously
• The setTimeout() and setInterval() are both
methods of the HTML DOM Window object
JAVASCRIPT TIMING EVENTS
How to Stop the Execution?
• The clearTimeout() method stops the execution
of the function specified in setTimeout()
• The clearInterval() method stops the
executions of the function specified in the
setInterval() method
JAVASCRIPT COOKIES
• Cookies are data, stored in small text files, on your
computer
• When a web server has sent a web page to a browser, the
connection is shut down, and the server forgets everything
about the user
• Cookies were invented to solve the problem "how to
remember information about the user":
• When a user visits a web page, his/her name can be stored in a
cookie
• Next time the user visits the page, the cookie "remembers"
his/her name
• Cookies are saved in name-value pairs like
• When a browser requests a web page from a server,
JAVASCRIPT COOKIES
Create a Cookie with JavaScript
• JavaScript can create, read, and delete cookies with the
document.cookie property
• With JavaScript, a cookie can be created like this:
• You can also add an expiry date (in UTC time). By
default, the cookie is deleted when the browser is
closed:
• With a path parameter, you can tell the browser what
path the cookie belongs to. By default, the cookie
belongs to the current page
JAVASCRIPT COOKIES
Read a Cookie with JavaScript
• With JavaScript, cookies can be read like this
• document.cookie will return all cookies in
one string much like: cookie1=value;
cookie2=value; cookie3=value;
JAVASCRIPT COOKIES
Change a Cookie with JavaScript
• With JavaScript, you can change a cookie the
same way as you create it
• The old cookie is overwritten
JAVASCRIPT COOKIES
Delete a Cookie with JavaScript
• Deleting a cookie is very simple
• You don't have to specify a cookie value when you
delete a cookie
• Just set the expires parameter to a passed date
• You should define the cookie path to ensure that
you delete the right cookie
• Some browsers will not let you delete a cookie if you
don't specify the path
JAVASCRIPT COOKIES
• The document.cookie property looks like a normal text
string, but it is not
• Even if you write a whole cookie string to
document.cookie, when you read it out again, you can
only see the name-value pair of it
• If you set a new cookie, older cookies are not overwritten.
The new cookie is added to document.cookie, so if you
read document.cookie again you will get something like:
cookie1 = value; cookie2 = value;
• If you want to find the value of one specified cookie, you
must write a JavaScript function that searches for the
cookie value in the cookie string
JAVASCRIPT LOCAL STORAGE
• localStorage is a way to store data on the client’s
computer
• It allows the saving of key/value pairs in a web
browser and it stores data with no expiration date
• localStorage can only be accessed via JavaScript,
and HTML5
• The user has the ability to clear the browser
data/cache to erase all localStorage data
JAVASCRIPT LOCAL STORAGE
• Web storage can be viewed simplistically as an
improvement on cookies, providing much greater
storage capacity
• The available size is 5MB, which is more space to work
with than a typical 4KB cookie
• In addition with localStorage, the data is not sent
back to the server for every HTTP request (HTML,
images, JavaScript, CSS, etc.), which thus reduces the
amount of traffic between client and server
• Lastly, it works on same-origin policy, so the data
stored will only be available on the same origin
JAVASCRIPT LOCAL STORAGE
• Storing data in localStorage
• Retrieving data from localStorage
• Deleting data from localStorage
EXAMPLE #01
• Create an HTML document in which the user
can input two resistance values and a
selectable connection type between them:
series or parallel
• The document should calculate the equivalent
resistance of the two inputs and display the
appropriate result
EXAMPLE #01
EXAMPLE #01
Why?
EXAMPLE #01
EXAMPLE #01
Identify possible
failure points of
EXAMPLE #02
• Create a script that validates an e-mail
address entered into a text field
• If the e-mail address is invalid upon the user
leaving the text field, its border will be
formatted red and a small alert will display
underneath, stating that the entered
information is not a valid e-mail address
EXAMPLE #02
• Rules for validation:
• Starts with a letter or number
• Contains exactly one “@” character
• Contains at least one “.” character
• The last “.” character is always after the “@”
character
• Bonus
• Trim whitespaces from the string before starting
validation
EXAMPLE #02
EXAMPLE #02
EXAMPLE #02
EXAMPLE #02
Identify possible
failure points of
the script!
EXAMPLE #02
The same thing,
using regular
expressions
EXAMPLE #03
• Create a page, that on the first visit asks the
user for their name, and then on each
subsequent visit, greats them with a custom
message: “Welcome, username!”
• The name of the user is stored for 10 days,
however, the solution should be flexible
EXAMPLE #03
HTML
CSS
EXAMPLE #03
EXAMPLE #03
EXAMPLE #03
EXAMPLE #04
• Write a page that is able to get data from the
user in the form of HH:MM:SS
• When the user sets a value and presses a
button, a countdown clock starts
• The countdown has a resolution of one
second, and at the end warns the user that the
given time has passed
EXAMPLE #04
EXAMPLE #04
Note that I did
not manually
populate the
selectors!
EXAMPLE #04
EXAMPLE #04
EXAMPLE #04
Why is this
necessary?
EXAMPLE #04
SCHEDULE FOR FINAL 4 WEEKS
Week Week span Activity
#11 09 – 15
December
C09: JavaScript – DOM
L09: JavaScript – DOM
#12 16 – 22
December
C10: JavaScript – JSON & AJAX
L10: JavaScript – JSON & AJAX
#13 06 – 12 January
Sat, 11 January
C11: jQuery
LT02 – Laboratory test #2: HTML + CSS +
JavaScript
FE – Final Exam: JavaScript + jQuery (C07 – C11)
#14 13 – 19 January C12: Angular
L11: jQuery
BIBLIOGRAPHY
• https://www.w3schools.com/js/js_htmldom.as
p
• https://www.w3schools.com/js/js_window.asp
COURSES
Available online at:
http://www.ael.utcluj.ro/
Information for Students -> Courses -> Web
Technologies
Web technologies-course 09.pptx

More Related Content

Similar to Web technologies-course 09.pptx (20)

Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
Html dom & j query
Html dom & j queryHtml dom & j query
Html dom & j query
 
javascript.pptx
javascript.pptxjavascript.pptx
javascript.pptx
 
javascript.pptx
javascript.pptxjavascript.pptx
javascript.pptx
 
Dom structure
Dom structureDom structure
Dom structure
 
Dom structures
Dom structuresDom structures
Dom structures
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Javascript part 2 DOM.pptx
Javascript part 2 DOM.pptxJavascript part 2 DOM.pptx
Javascript part 2 DOM.pptx
 
HTML_DOM
HTML_DOMHTML_DOM
HTML_DOM
 
Dom
DomDom
Dom
 
FYBSC IT Web Programming Unit III Document Object
FYBSC IT Web Programming Unit III  Document ObjectFYBSC IT Web Programming Unit III  Document Object
FYBSC IT Web Programming Unit III Document Object
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
Web design - HTML (Hypertext Markup Language) introduction
Web design - HTML (Hypertext Markup Language) introductionWeb design - HTML (Hypertext Markup Language) introduction
Web design - HTML (Hypertext Markup Language) introduction
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & event
 
6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389 (1).ppt
6867389 (1).ppt6867389 (1).ppt
6867389 (1).ppt
 
Basic web security model
Basic web security modelBasic web security model
Basic web security model
 

More from Stefan Oprea

Training-Book-Samsung.ppt
Training-Book-Samsung.pptTraining-Book-Samsung.ppt
Training-Book-Samsung.pptStefan Oprea
 
PRESENTATION ON TOUCH TECHNOLOGY.ppt
PRESENTATION ON TOUCH TECHNOLOGY.pptPRESENTATION ON TOUCH TECHNOLOGY.ppt
PRESENTATION ON TOUCH TECHNOLOGY.pptStefan Oprea
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
Web technologies-course 11.pptx
Web technologies-course 11.pptxWeb technologies-course 11.pptx
Web technologies-course 11.pptxStefan Oprea
 
Web technologies-course 10.pptx
Web technologies-course 10.pptxWeb technologies-course 10.pptx
Web technologies-course 10.pptxStefan Oprea
 
Web technologies-course 08.pptx
Web technologies-course 08.pptxWeb technologies-course 08.pptx
Web technologies-course 08.pptxStefan Oprea
 
Web technologies-course 07.pptx
Web technologies-course 07.pptxWeb technologies-course 07.pptx
Web technologies-course 07.pptxStefan Oprea
 
Web technologies-course 06.pptx
Web technologies-course 06.pptxWeb technologies-course 06.pptx
Web technologies-course 06.pptxStefan Oprea
 
Web technologies-course 05.pptx
Web technologies-course 05.pptxWeb technologies-course 05.pptx
Web technologies-course 05.pptxStefan Oprea
 
Web technologies-course 04.pptx
Web technologies-course 04.pptxWeb technologies-course 04.pptx
Web technologies-course 04.pptxStefan Oprea
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptxStefan Oprea
 
Web technologies-course 02.pptx
Web technologies-course 02.pptxWeb technologies-course 02.pptx
Web technologies-course 02.pptxStefan Oprea
 
Web technologies-course 01.pptx
Web technologies-course 01.pptxWeb technologies-course 01.pptx
Web technologies-course 01.pptxStefan Oprea
 
Fundamentals of Digital Modulation.ppt
Fundamentals of Digital Modulation.pptFundamentals of Digital Modulation.ppt
Fundamentals of Digital Modulation.pptStefan Oprea
 
Orthogonal Frequency Division Multiplexing.ppt
Orthogonal Frequency Division Multiplexing.pptOrthogonal Frequency Division Multiplexing.ppt
Orthogonal Frequency Division Multiplexing.pptStefan Oprea
 
Modulation tutorial.ppt
Modulation tutorial.pptModulation tutorial.ppt
Modulation tutorial.pptStefan Oprea
 
Comparison of Single Carrier and Multi-carrier.ppt
Comparison of Single Carrier and Multi-carrier.pptComparison of Single Carrier and Multi-carrier.ppt
Comparison of Single Carrier and Multi-carrier.pptStefan Oprea
 
OFDM and MC-CDMA An Implementation using MATLAB.ppt
OFDM and MC-CDMA An Implementation using MATLAB.pptOFDM and MC-CDMA An Implementation using MATLAB.ppt
OFDM and MC-CDMA An Implementation using MATLAB.pptStefan Oprea
 
Concepts of 3GPP LTE.ppt
Concepts of 3GPP LTE.pptConcepts of 3GPP LTE.ppt
Concepts of 3GPP LTE.pptStefan Oprea
 
Multi-Carrier Transmission over Mobile Radio Channels.ppt
Multi-Carrier Transmission over Mobile Radio Channels.pptMulti-Carrier Transmission over Mobile Radio Channels.ppt
Multi-Carrier Transmission over Mobile Radio Channels.pptStefan Oprea
 

More from Stefan Oprea (20)

Training-Book-Samsung.ppt
Training-Book-Samsung.pptTraining-Book-Samsung.ppt
Training-Book-Samsung.ppt
 
PRESENTATION ON TOUCH TECHNOLOGY.ppt
PRESENTATION ON TOUCH TECHNOLOGY.pptPRESENTATION ON TOUCH TECHNOLOGY.ppt
PRESENTATION ON TOUCH TECHNOLOGY.ppt
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
Web technologies-course 11.pptx
Web technologies-course 11.pptxWeb technologies-course 11.pptx
Web technologies-course 11.pptx
 
Web technologies-course 10.pptx
Web technologies-course 10.pptxWeb technologies-course 10.pptx
Web technologies-course 10.pptx
 
Web technologies-course 08.pptx
Web technologies-course 08.pptxWeb technologies-course 08.pptx
Web technologies-course 08.pptx
 
Web technologies-course 07.pptx
Web technologies-course 07.pptxWeb technologies-course 07.pptx
Web technologies-course 07.pptx
 
Web technologies-course 06.pptx
Web technologies-course 06.pptxWeb technologies-course 06.pptx
Web technologies-course 06.pptx
 
Web technologies-course 05.pptx
Web technologies-course 05.pptxWeb technologies-course 05.pptx
Web technologies-course 05.pptx
 
Web technologies-course 04.pptx
Web technologies-course 04.pptxWeb technologies-course 04.pptx
Web technologies-course 04.pptx
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
 
Web technologies-course 02.pptx
Web technologies-course 02.pptxWeb technologies-course 02.pptx
Web technologies-course 02.pptx
 
Web technologies-course 01.pptx
Web technologies-course 01.pptxWeb technologies-course 01.pptx
Web technologies-course 01.pptx
 
Fundamentals of Digital Modulation.ppt
Fundamentals of Digital Modulation.pptFundamentals of Digital Modulation.ppt
Fundamentals of Digital Modulation.ppt
 
Orthogonal Frequency Division Multiplexing.ppt
Orthogonal Frequency Division Multiplexing.pptOrthogonal Frequency Division Multiplexing.ppt
Orthogonal Frequency Division Multiplexing.ppt
 
Modulation tutorial.ppt
Modulation tutorial.pptModulation tutorial.ppt
Modulation tutorial.ppt
 
Comparison of Single Carrier and Multi-carrier.ppt
Comparison of Single Carrier and Multi-carrier.pptComparison of Single Carrier and Multi-carrier.ppt
Comparison of Single Carrier and Multi-carrier.ppt
 
OFDM and MC-CDMA An Implementation using MATLAB.ppt
OFDM and MC-CDMA An Implementation using MATLAB.pptOFDM and MC-CDMA An Implementation using MATLAB.ppt
OFDM and MC-CDMA An Implementation using MATLAB.ppt
 
Concepts of 3GPP LTE.ppt
Concepts of 3GPP LTE.pptConcepts of 3GPP LTE.ppt
Concepts of 3GPP LTE.ppt
 
Multi-Carrier Transmission over Mobile Radio Channels.ppt
Multi-Carrier Transmission over Mobile Radio Channels.pptMulti-Carrier Transmission over Mobile Radio Channels.ppt
Multi-Carrier Transmission over Mobile Radio Channels.ppt
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Web technologies-course 09.pptx

  • 1.
  • 2. COURSE 09 JAVASCRIPT lect. eng. Rajmond JÁNÓ, PhD rajmond.jano@ael.utcl uj.ro fb.com/janorajmond
  • 3. C09 – JAVASCRIPT • HTML DOM • HTML BOM • Popup boxes • Timing events • Cookies • Local storage • Examples
  • 4. JAVASCRIPT HTML DOM • With the HTML DOM, JavaScript can access and change all the elements of an HTML document • When a web page is loaded, the browser creates a Document Object Model of the page
  • 5. JAVASCRIPT HTML DOM • The HTML DOM model is constructed as a tree of Objects
  • 6. JAVASCRIPT HTML DOM With the object model, JavaScript gets all the power it needs to create dynamic HTML. JavaScript can: • Change all the HTML elements in the page • Change all the HTML attributes in the page • Change all the CSS styles in the page • Remove existing HTML elements and attributes • Add new HTML elements and attributes • React to all existing HTML events in the page • Create new HTML events in the page
  • 7. JAVASCRIPT HTML DOM • The DOM is a W3C (World Wide Web Consortium) standard • The DOM defines a standard for accessing documents: "The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document." • The W3C DOM standard is separated into 3 different parts: • Core DOM - standard model for all document types • XML DOM - standard model for XML documents • HTML DOM - standard model for HTML documents
  • 8. JAVASCRIPT HTML DOM The HTML DOM is a standard object model and programming interface for HTML. It defines: • The HTML elements as objects • The properties of all HTML elements • The methods to access all HTML elements • The events for all HTML elements In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
  • 9. JAVASCRIPT HTML DOM METHODS • HTML DOM methods are actions you can perform (on HTML Elements) • HTML DOM properties are values (of HTML Elements) that you can set or change
  • 10. JAVASCRIPT HTML DOM METHODS The DOM Programming Interface • The HTML DOM can be accessed with JavaScript (and with other programming languages) • In the DOM, all HTML elements are defined as objects • The programming interface is the properties and methods of each object • A property is a value that you can get or set (like changing the content of an HTML element) • A method is an action you can do (like add or deleting an HTML element)
  • 11. JAVASCRIPT HTML DOM DOCUMENT • The HTML DOM document object is the owner of all other objects in your web page • The document object represents your web page • If you want to access any element in an HTML page, you always start with accessing the document object
  • 12. JAVASCRIPT HTML DOM ELEMENTS • Often, with JavaScript, you want to manipulate HTML elements • To do so, you have to find the elements first. There are several ways to do this: • Finding HTML elements by id • Finding HTML elements by tag name • Finding HTML elements by class name • Finding HTML elements by CSS selectors • Finding HTML elements by HTML object collections
  • 13. JAVASCRIPT HTML DOM ELEMENTS • The easiest way to find an HTML element in the DOM, is by using the element id • If the element is found, the method will return the element as an object (in myElement) • If the element is not found, myElement will contain null
  • 14. JAVASCRIPT HTML DOM ELEMENTS • Finding HTML Elements by Tag Name
  • 15. JAVASCRIPT HTML DOM ELEMENTS • Finding HTML Elements by Class Name • If you want to find all HTML elements with the same class name, use getElementsByClassName()
  • 16. JAVASCRIPT HTML DOM ELEMENTS • Finding HTML Elements by CSS Selectors • If you want to find all HTML elements that match a specified CSS selector (id, class names, types, attributes, values of attributes, etc), use the querySelectorAll() method
  • 17. JAVASCRIPT HTML DOM ELEMENTS • Finding HTML Elements by HTML Object Collections • The following HTML objects (and object collections) are also accessible: • document.anchors • document.body • document.documentElement • document.embeds • document.forms • document.head • document.images • document.links • document.scripts • document.title
  • 18. CHANGING THE HTML OUTPUT STREAM • JavaScript can create dynamic HTML content • In JavaScript, document.write() can be used to write directly to the HTML output stream Never use document.write()after the document is loaded. It will overwrite the document content.
  • 19. CHANGING HTML CONTENT • The easiest way to modify the content of an HTML element is by using the innerHTML property. • To change the content of an HTML element, use this syntax
  • 20. CHANGING THE VALUE OF AN ATTRIBUTE • To change the value of an HTML attribute, use this syntax
  • 21. JAVASCRIPT HTML DOM – CHANGING CSS • The HTML DOM allows JavaScript to change the style of HTML elements • Changing HTML Style • To change the style of an HTML element, use this syntax
  • 22. JAVASCRIPT HTML DOM – CHANGING CSS • The HTML DOM also allows JavaScript to manipulate the CSS classes of HTML elements • Setting classes • Adding classes • Removing classes • Toggling classes
  • 23. JAVASCRIPT HTML DOM EVENTS • HTML DOM allows JavaScript to react to HTML events • A JavaScript can be executed when an event occurs, like when a user clicks on an HTML element • Examples of HTML events: • When a user clicks the mouse • When a web page has loaded • When an image has been loaded • When the mouse moves over an element • When an input field is changed • When an HTML form is submitted • When a user strokes a key
  • 24. ADDING EVENTS There are three ways to add events to HTML elements • HTML event attributes • Assigning events using the HTML DOM • Adding an event listener using the addEventListener() method Please avoid this method, use the other two!
  • 25. EVENT BUBBLING OR EVENT CAPTURING • The same HTML element can have multiple events and HTML elements embedded into each other can have different functions defined for the same event • So in what order to these events get executed, then?
  • 26. EVENT BUBBLING OR EVENT CAPTURING There are two ways of event propagation in the HTML DOM, bubbling and capturing • Event propagation is a way of defining the element order when an event occurs • If you have a <p> element inside a <div> element, and the user clicks on the <p> element, which element's "click" event should be handled first? • In bubbling the inner most element's event is handled first and then the outer • The <p> element's click event is handled first, then the <div> element's click event • In capturing the outer most element's event is handled first and then the inner • The <div> element's click event will be handled first, then the <p> element's click event
  • 27. EVENT BUBBLING OR EVENT CAPTURING With the addEventListener() method you can specify the propagation type by using the useCapture parameter
  • 28. JAVASCRIPT HTML DOM NAVIGATION With the HTML DOM, you can navigate the node tree using node relationships. DOM Nodes According to the W3C HTML DOM standard, everything in an HTML document is a node: • The entire document is a document node • Every HTML element is an element node • The text inside HTML elements are text nodes • All comments are comment nodes
  • 29. JAVASCRIPT HTML DOM NAVIGATION • With the HTML DOM, all nodes in the node tree can be accessed by JavaScript • New nodes can be created, and all nodes can be modified or deleted
  • 30. NODE RELATIONSHIPS • The nodes in the node tree have a hierarchical relationship to each other • The terms parent, child, and sibling are used to describe the relationships • In a node tree, the top node is called the root (or root node) • Every node has exactly one parent, except the root (which has no parent) • A node can have a number of children • Siblings (brothers or sisters) are nodes with the same parent
  • 31. NODE RELATIONSHIPS From the HTML above you can read: <html> is the root node <html> has no parents <html> is the parent of <head> and <body> <head> is the first child of <html> <body> is the last child of <html> and: <head> has one child: <title> <title> has one child (a text node): "DOM Tutorial" <body> has two children: <h1> and <p> <h1> has one child: "DOM Lesson one" <p> has one child: "Hello world!" <h1> and <p> are siblings
  • 32. NAVIGATING BETWEEN NODES • You can use the following node properties to navigate between nodes with JavaScript: • parentNode • childNodes[nodenumber] • firstChild • lastChild • nextSibling • previousSibling
  • 33. CHILD NODES AND NODE VALUES • A common error in DOM processing is to expect an element node to contain text • The element node <title> (in the example above) does not contain text • It contains a text node with the value "DOM Tutorial" • The value of the text node can be accessed by the node's innerHTML property: • Accessing the innerHTML property is the same as accessing the nodeValue of the first child: • Accessing the first child can also be done like this:
  • 34. DOM ROOT NODES There are two special properties that allow access to the full document: • document.body – The body of the document • document.documentElement – The full document
  • 35. CREATING NEW HTML ELEMENTS (NODES) • To add a new element to the HTML DOM, you must create the element (element node) first, and then append it to an existing element
  • 36. THE BROWSER OBJECT MODEL (BOM) • The Browser Object Model (BOM) allows JavaScript to "talk to" the browser • There are no official standards for the BOM • Since modern browsers have implemented (almost) the same methods and properties for JavaScript interactivity, it is often referred to, as methods and properties of the BOM
  • 37. THE WINDOW OBJECT • The window object is supported by all browsers. It represents the browser's 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
  • 38. WINDOW SIZE AND METHODS • Two properties can be used to determine the size of the browser window • Both properties return the sizes in pixels: • window.innerHeight – the inner height of the browser window (in pixels) • window.innerWidth – the inner width of the browser window (in pixels) The browser window (the browser viewport) is NOT including toolbars and scrollbars.
  • 39. WINDOW SIZE AND METHODS • Some other window methods: • window.open() – open a new window • window.close() – close the current window • window.moveTo() – move the current window • window.resizeTo() – resize the current window
  • 40. JAVASCRIPT WINDOW SCREEN • The window.screen object contains information about the user's screen • The window.screen object can be written without the window prefix • Properties: • screen.width – returns the width of the visitor's screen in pixels • screen.height – returns the height of the visitor's screen in pixels • screen.availWidth – returns the width of the visitor's screen, in pixels, minus interface features like the Windows Taskbar • screen.availHeight – returns the height of the visitor's screen, in pixels, minus interface features like the Windows Taskbar • screen.colorDepth – returns the number of bits used to display one color
  • 41. JAVASCRIPT WINDOW LOCATION • The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page • The window.location object can be written without the window prefix • Some examples: • window.location.href – returns the href (URL) of the current page • window.location.hostname – returns the domain name of the web host • window.location.pathname – returns the path and filename of the current page • window.location.protocol – returns the web protocol used (http: or https:)
  • 42. JAVASCRIPT WINDOW HISTORY • The window.history object contains the browsers history • The window.history object can be written without the window prefix • To protect the privacy of the users, there are limitations to how JavaScript can access this object • Some methods: • history.back() – same as clicking back in the browser • history.forward() – same as clicking forward in the browser
  • 43. JAVASCRIPT WINDOW NAVIGATOR • The window.navigator object contains information about the visitor's browser • The window.navigator object can be written without the window prefix
  • 44. JAVASCRIPT WINDOW NAVIGATOR • Browser Cookies • The cookieEnabled property returns true if cookies are enabled, otherwise false • Browser Application Name • The appName property returns the application name of the browser • "Netscape" is the application name for both IE11, Chrome, Firefox, and Safari
  • 45. JAVASCRIPT WINDOW NAVIGATOR • Browser Application Code Name • The appCodeName property returns the application code name of the browser • "Mozilla" is the application code name for both Chrome, Firefox, IE, Safari, and Opera • The Browser Engine • The product property returns the product name of the browser engine • Do not rely on this, most browsers return "Gecko" as product name
  • 46. JAVASCRIPT WINDOW NAVIGATOR • The Browser Version • The appVersion property returns version information about the browser • The Browser Agent • The userAgent property returns the user-agent header sent by the browser to the server
  • 47. JAVASCRIPT WINDOW NAVIGATOR • The information from the navigator object can often be misleading, and should not be used to detect browser versions because: • Different browsers can use the same name • The navigator data can be changed by the browser owner • Some browsers misidentify themselves to bypass site tests • Browsers cannot report new operating systems, released later than the browser
  • 48. JAVASCRIPT WINDOW NAVIGATOR • The Browser Platform • The platform property returns the browser platform (operating system) • The Browser Language • The language property returns the browser's language • Is The Browser Online? • The onLine property returns true if the browser is online • Is Java Enabled?
  • 49. JAVASCRIPT POPUP BOXES Alert Box • An alert box is often used if you want to make sure information comes through to the user • When an alert box pops up, the user will have to click "OK" to proceed
  • 50. JAVASCRIPT POPUP BOXES Confirm Box • A confirm box is often used if you want the user to verify or accept something • When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. • If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false
  • 52. JAVASCRIPT POPUP BOXES Prompt Box • A prompt box is often used if you want the user to input a value before entering a page • When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value • If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null
  • 54. JAVASCRIPT TIMING EVENTS • The window object allows execution of code at specified time intervals • These time intervals are called timing events • The two key methods to use with JavaScript are: • setTimeout(function, milliseconds) • Executes a function, after waiting a specified number of milliseconds • setInterval(function, milliseconds) • Same as setTimeout(), but repeats the execution of the function continuously • The setTimeout() and setInterval() are both methods of the HTML DOM Window object
  • 55. JAVASCRIPT TIMING EVENTS How to Stop the Execution? • The clearTimeout() method stops the execution of the function specified in setTimeout() • The clearInterval() method stops the executions of the function specified in the setInterval() method
  • 56. JAVASCRIPT COOKIES • Cookies are data, stored in small text files, on your computer • When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user • Cookies were invented to solve the problem "how to remember information about the user": • When a user visits a web page, his/her name can be stored in a cookie • Next time the user visits the page, the cookie "remembers" his/her name • Cookies are saved in name-value pairs like • When a browser requests a web page from a server,
  • 57. JAVASCRIPT COOKIES Create a Cookie with JavaScript • JavaScript can create, read, and delete cookies with the document.cookie property • With JavaScript, a cookie can be created like this: • You can also add an expiry date (in UTC time). By default, the cookie is deleted when the browser is closed: • With a path parameter, you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page
  • 58. JAVASCRIPT COOKIES Read a Cookie with JavaScript • With JavaScript, cookies can be read like this • document.cookie will return all cookies in one string much like: cookie1=value; cookie2=value; cookie3=value;
  • 59. JAVASCRIPT COOKIES Change a Cookie with JavaScript • With JavaScript, you can change a cookie the same way as you create it • The old cookie is overwritten
  • 60. JAVASCRIPT COOKIES Delete a Cookie with JavaScript • Deleting a cookie is very simple • You don't have to specify a cookie value when you delete a cookie • Just set the expires parameter to a passed date • You should define the cookie path to ensure that you delete the right cookie • Some browsers will not let you delete a cookie if you don't specify the path
  • 61. JAVASCRIPT COOKIES • The document.cookie property looks like a normal text string, but it is not • Even if you write a whole cookie string to document.cookie, when you read it out again, you can only see the name-value pair of it • If you set a new cookie, older cookies are not overwritten. The new cookie is added to document.cookie, so if you read document.cookie again you will get something like: cookie1 = value; cookie2 = value; • If you want to find the value of one specified cookie, you must write a JavaScript function that searches for the cookie value in the cookie string
  • 62. JAVASCRIPT LOCAL STORAGE • localStorage is a way to store data on the client’s computer • It allows the saving of key/value pairs in a web browser and it stores data with no expiration date • localStorage can only be accessed via JavaScript, and HTML5 • The user has the ability to clear the browser data/cache to erase all localStorage data
  • 63. JAVASCRIPT LOCAL STORAGE • Web storage can be viewed simplistically as an improvement on cookies, providing much greater storage capacity • The available size is 5MB, which is more space to work with than a typical 4KB cookie • In addition with localStorage, the data is not sent back to the server for every HTTP request (HTML, images, JavaScript, CSS, etc.), which thus reduces the amount of traffic between client and server • Lastly, it works on same-origin policy, so the data stored will only be available on the same origin
  • 64. JAVASCRIPT LOCAL STORAGE • Storing data in localStorage • Retrieving data from localStorage • Deleting data from localStorage
  • 65. EXAMPLE #01 • Create an HTML document in which the user can input two resistance values and a selectable connection type between them: series or parallel • The document should calculate the equivalent resistance of the two inputs and display the appropriate result
  • 70. EXAMPLE #02 • Create a script that validates an e-mail address entered into a text field • If the e-mail address is invalid upon the user leaving the text field, its border will be formatted red and a small alert will display underneath, stating that the entered information is not a valid e-mail address
  • 71. EXAMPLE #02 • Rules for validation: • Starts with a letter or number • Contains exactly one “@” character • Contains at least one “.” character • The last “.” character is always after the “@” character • Bonus • Trim whitespaces from the string before starting validation
  • 75. EXAMPLE #02 Identify possible failure points of the script!
  • 76. EXAMPLE #02 The same thing, using regular expressions
  • 77. EXAMPLE #03 • Create a page, that on the first visit asks the user for their name, and then on each subsequent visit, greats them with a custom message: “Welcome, username!” • The name of the user is stored for 10 days, however, the solution should be flexible
  • 82. EXAMPLE #04 • Write a page that is able to get data from the user in the form of HH:MM:SS • When the user sets a value and presses a button, a countdown clock starts • The countdown has a resolution of one second, and at the end warns the user that the given time has passed
  • 84. EXAMPLE #04 Note that I did not manually populate the selectors!
  • 87. EXAMPLE #04 Why is this necessary?
  • 89. SCHEDULE FOR FINAL 4 WEEKS Week Week span Activity #11 09 – 15 December C09: JavaScript – DOM L09: JavaScript – DOM #12 16 – 22 December C10: JavaScript – JSON & AJAX L10: JavaScript – JSON & AJAX #13 06 – 12 January Sat, 11 January C11: jQuery LT02 – Laboratory test #2: HTML + CSS + JavaScript FE – Final Exam: JavaScript + jQuery (C07 – C11) #14 13 – 19 January C12: Angular L11: jQuery
  • 91. COURSES Available online at: http://www.ael.utcluj.ro/ Information for Students -> Courses -> Web Technologies

Editor's Notes

  1. Failure points of the script: - Decimal numbers will be treated as integers -> will not accept decimal values lower than 1 (e.g.: 0.1) Accepts text as input, but will return “NaN” as a result Possible resolution loss due to rounding to 3 decimals