TCU BO ccncson
MULTIMEDIA IN THE WEB
brovisers; often they have no suppor at all in older browsers, Together thse factors make it
difficult to deliver audio and video that’s consistently playable for all of your vistors
The addition of the
and tags in HTMLS makes the process of delivering
and playing video and audio more straightforward. Playing multimedia will get easier over
time as newer browsers support the tags and people upgrade their older browsers
Traditionally, developers and.designers have most ‘commonly set up pages to play video and
audio on the Web using Adobe Flash. Sites such as YouTube (http:/www.youtube.cam)
embed video inside of a Flash file. This requires thatthe end user has the Adobe Flash player
installed,
The HTMLS specification introduces an alternative to that: a standard tag, , which
enables the playing of video content, However, the tag still requires a video fileand
also requires end users to have an appropriate player installed on their-computers. For aio
clips, the traditional delivery method has been to use the or tag to embed a
clip on a page. HTMLS provides the tag to do this instead, :
AS of this writing, the and tags have limited support in Web browses,
Adding to the complexity is the need to support multiple formats for video, depending on
what your visitor's browser can play,
Browsers that don’t support these tags ignore them, but if you want to deliver your audio or
video to a full range of browsers—new and old, you'll need to be able to do it without the we
of these tags. This chapter shows both the old and new methods.
Embedding Video File
The basic form of Video tag looks is as follows:
‘filename.extention" >
tag that make it more configurable for your nosis
and the needs of your audience. The atttibutes include;
¥ Autoplay — autoplay attribute makes the video automatically play when the page is
loaded,
Y Controls this determines whether a default set of playback controls should be visible
within the browser. This attribute allow user'to play, pause, stop etc the video without
reloading the entire page.
Jd
~y
ie
Scanned with CamScanner*
rs nae
—
‘ATBU_DNS_CS242_2019/2020
Y Loop ~ loop attribute tells the browser to restart the video immediately when it's
finished playing
Y Preload - The preload attribute tells the browser to begin downloading the video
immediately when the clement is encountered. If the video is the central theme ofthe
page, and it’s likely that all (or most) visitors wall want to watch the video, then it’s a
200d idea to use the preload option. However, if the video element is a small part of
the page and visitors aren't likely to watch it, then preloading the video is just a waste
of bandwidth
Y Width
Y Height
. Incorporating Audio on Web Page
Like the tag, the tag supports multiple sources. With no common format,
you'll need to encode the audio multiple times to try to get the audio out to the widest
” possible audience. Also like the tag, the tag supports attributes such as
controls, autoplay, loop, and preload, Therefore, the syntax for the tag is essentially
the same as the syntax for the tag.
Take a look at the following interface where audio player was inserted on the page using
audio tag.
—e
> 00
JAVASCRIPT
What is JavaScript?
JavaScript is a computer programming language used in the presentation tier (layer) of web
applications. It is lightweight and most commonly used in design of web pages. It is an
interpreted programming language with object-oriented eapabilities. JavaScript enable web
page to include programs that interact with the user, control the browser, and dynamically
create HTML content, JavaScript code executes within a browser. JavaScript code is
embedded within an HTML page using the JavaScript tag. :
It is important to note that JavaScript is not the same as Java, They are two different
languages. However, both have similar syntax of their contol structures. :
What can be done with JavaScript?
i, JavaScript can be used for input validation ~ JavaScript can be used to check whether
form fields or data are valid before submitting for further server side processing. eg,
check if user has entered a valid e-mail address in a form field,
~~
~
Scanned with CamScanner: - ATBU_OMS_¢s212 2019/2039
fi, JavaScript can be used to trap user-initiat
navigation, and other actions that the user init
iii, JavaScript can use to include items such
calendar ete inorder to give a rich Interface o your site visitors
1, JavaScript can be used to send request to server asynchronously, using the technique
called AJAX (Asynchronous JavaScript and Xml),
ted events such as button clicks, lik
iates explicitly or implicitly,
as drag-and-drop components, sliders,
Limitations of JavaScript
There are many tasks that JavaScript can't handle
Browsers can disable JavaScript,
JavaScriptis a Client-side language and does not allow the Teading or writing of files
JavaScript doesn't have any multithreading or multiprocessor capabilities.
iv. JavaScript cannot be used for connectivity to databases
Development Tool
One of the major strengths of JavaScript is that it does not require expensive development
‘ools, You ean start with a simple text editor such as Notepad, Notepads Development
Environments such as; Eclipse, Netbeans, Macromedia Dreamweaver, Front page also
Provides developers with ability to create and manipulate JavaScript codes.
JavaScript Library and Frameworks
Over time, several JavaScript libraries and frameworks have been developed. Generally, a
library is a reusable piece of code that oftentimes has one primary use case. A library cn
consist of several functions/objects/methods, depending on the language. Your application
can “link” to a library to allow you access to that functionality. On the other hand, a
framework has more control of your app. It helps direct you on the architecture and the
project that follows, Frameworks consist of multiple libraries and they provide you with
hooks and callbacks, so you can continue to build upon them, Both are useful and it's a good
‘dea to experiment and see which ones work best for you.
iQuery ~ jQuery is a library used primarily for Document Object Model (DOM)
manipulation. The DOM is a tree-like structure thet represents all elements on a webpage,
iQuery can select DOM elements, ereate animations, handle events, and more. Iis goal sto
be extensible, simple, and clear to use. It takes care of all cross-browser incompaibilies
Should you use jQuery? Well, it depends. Some websites insist that jQuery is no longer
needed. Modern browsers have greatly improved their DOM Application Programming
Interfaces (API). In the past, you might have used jQuery to do simple query selections. You
can now easily do that with plain old JavaScript. Furthermore, with the popularity of single-
page-application (SPA) frameworks it doesn't make sense to use jQuery in many
circumstances. For example, most SPAs have some sort of event handling built in. Using
jQuery could cause more harm than good in these cases. At the very least, you should learn
the basies of jQuery as a new web developer. You will almost certainly run into older code
bases that use jQuery, and it does come in handy in other scenarios from time to time,
3
on . oa
= =
Scanned with CamScannerr , ATOUONS,_CS212_ 2029/2
React = isa JavaScript library for building User Interfaces (UIs) With React, one ean ae
interactive Uls, design simple views for each state in the application
AngulardS ~ is an opensouree JavaScript ftamowork created and maintained by Google
is a fhontond tramework that helps you eteate web applications It aims to simplify boththe
evelopment and the testing of such applications by providing a framework for clintside
tmodel-view-eontrollet (MVC) ant model-view-view model (MVVM) architectures, ng
with components commonly used in rich Internet applications, The AngulardS framework
works by frst reading the Hypertext Mark-up Language (HTML) page, which has addlioeal
custom HTML attributes embedded into it, It interprets those attributes as directives to bind
input or output parts of the page to a model that is represented by standard JavaSetp
variables. The values of these JavaScript variables ean be manually set within the code, or
retrieved thom static or dynamic JSON resources,
Vue js = is an open-source JavaSeripy framework for building user interfaces and singhegage
applications, It's been rewritten and refined into a great SPA. It is described as a MVM
pattemed framework, Model-View View-Model, whieh is based on the concept of rwo-wy
dinading data to components and views. It is ineredbly fast, exceeding speeds of other toptir
JS frameworks, and very user friendly for easy integration and prototyping, One of Vue's
greatest strengths is its progressiveness. In other words, you can progeessively add Vase into
your application, Unlike AngularJS and Ember, you can eas and match Vue into
projects. Some of its features include components, templates, transitions,"and two-way data
binding, as well as a focus on reactivity,
Nodes ~ Node,js is an open-source, cross-platform JavaScript run-time environment tht
executes JavaScript code outside of a browser. Node,js is primarily used to build network
programs such as Web servers. Node, allows the creation of Web servers and networking tools wing
JavaScript and a collection of "modules" that handle various core functionalities, Modules are
provided for file system VO, networking (DNS, HTTP, TCP, TLS/SSL, or UDP), binary data
(buffers), cryptography functions, data streams, and other core functions, Nodejs's modules use an
‘of writing server applications,
API designed to reduce the complexi
Embedding JavaScript Code in a web page
JavaScript code can be embedded in the page using the following ways:
Calling/Invoking Function
To invoke a function somewhere later in the script, you would simply need to write the name
of that function and the supply the parameters enclosed in parenthesis.
Example2: In the following examples, a button is created on the page. When this button is
clicked, the javaScript function, sayHello is invoked and the statements within the function
are executed.
Click this button please.
:
Scanned with CamScannerATBUDMS,.C5212_2919/i809
Example3: The following example retrieved value entered jn the tent bon ent den
concatenate it with another text, and finally display the resulting text in alert dialog box
‘serine typenttoxt/ javascript»
<
var defaultText * "This 4s 35 function demo";
function check() {
var valEntered * docunent , goté i
var v = dofaultText + valénterod;
alert(v);
ty Td("textboxt"), values
a
FA11 this form please,
|
: |
In example 3, defaultText variable is a global variable, while valEntered and v are Socal
variables. .
JavaScript and Forms
When the user clicks on a form’s Submit button, without JavaScript intervention, the fora’s
data is sent straight to the server for processing, But you can intercept the data (so you ex
process it with JavaScript) before itis sent,
Without JavaScript, the server handles all validating and processing of information submited
via a form. Using JavaScript on the client side of the equation saves time for the user and
creates a more efficient process. Some processing can be handled by JavaScript (for examgle,
ensure that only correct data is sent to the server for processing. JavaScript is used in
conjunction with server-side processing = itis not a substitute for it
With JavaScript, one can intercept form and process its content by
1. Including the onsubmit event handler in the
2, Including the onclick event handler in the submit button tag.
“
8
ea
Scanned with CamScanner* ATBU_DMS_CS212_2619/2020
stringVal:
var stringval = docunent. getélenent@yId( Enquiry”).valuey
JavaScript Events
SE TTT
_omuntoag ‘Occurs when docunent is removed from a window orf
‘onclick The mouse is clicked on on | ce ts —_
oxseiat ——[Tiegaubat nt
eaousior Hose amet
onmouseover Mouse moves outo an element 7
sacs [Benen to
sata Ee eee
suegen—[Rerguna
evo — [eet
eaten [Revise
‘onreset ‘Forn reset event occurs r
oie cae aa
Exampleé: the following example performs validation. It checks whether a textbox is empty
or not.
|
7
submit” />
Cinput type="button” onclick="check()" value
have used if statement and we didn’t discuss it. JavaScript support the stme
Java and PHP. So if you are familiar with the syntax of 7
In example4, we
control structure used in C,C+,
Scanned with CamScannerATBU_DMS_CS212_2019/2020
statement, while loop, for loop etc in tho:
JavaScript. P se languages, you can equally use the same syntain
DOCUMENT OBJECT MODEL
The DOM Serves as the interface between JavaScript and a web page; it provides a
representation of the HTML document as a network of objects rather than as plain text, This
network takes the form of a tree of elements ‘on the page. Thus, the Document Object Model
is a tree structure of various elements of HTML document.
The Document object Provides access to all of the HTML elements of the current page. We
have used document object in example 3 and 4.
iQuery *
jQuery is a fast and concise JavaScript library created by John Resig in 2006. jQuery
simplifies HTML document traversing, event handling, animating, and Ajax interactions for
Rapid Web Development. jQuery is a framework built using JavaScript capabilities. So, you
can use all the functions and other capabilities available in JavaScript. jQuery is de
simplify various tasks by writing less code. Here is the list of important core feanres
supported by jQuery:
¥ DOM manipulation: The jQuery made it easy to select DOM elements, negotiate
them and modifying their content by using cross-browser open source selector engine
called Sizzle.
¥ Event handling: The jQuery offers an elegant way to capture a wide variety of
events, such as a user clicking on a link, without the need to clutter the HTML cade
itself with event handlers.
Y AJAX Support: The jQuery helps you a lot to develop a responsive and featuresich
site using AJAX technology.
Y Animations: The jQuery comes with plenty of bul
can use in your websites.
Y Lightweight: The jQuery is very lightweight library - about 19KB in size (Minted
and gzipped).
animation effects which you
Using jQuery
It is important tp understand that jQuery reads or manipulates the document object mel
(DOM). All the jQuery codes executes as soon as the DOM is ready. This means eray
jQuery code must be inside $(document).ready() function. Everything inside it will loadas
‘soon as the DOM is loaded and before the page contents are loaded. The following is he
syntax:
$(document). ready (Function() { ;
7/ do stuff when 00% is ready
vs
10
Scanned with CamScannerATBU_DMS_CS212_2019/2828 :
jQuery Selectors
The jQuery library hamesses the power of Cascading Style Sheets (CSS) selectors to let us
quickly and easily access elements or groups of elements in the Document Object Model. A
‘jQuery Selector is a function which makes use of expressions to find out matching elements
from a DOM based on the given criteria.
We use jQuery selector to refer to individual elements in the document (DOM).
‘The selectors are very usefull and would be required at every step while using jQuery. They
enable you to get the exact element from your HTML document. Following table lists down
basic selectors and explains how to use them with examples.
Sn | Selector [Description Syntax
NAME __| Selects all elements which match | S(tagname})
selector___| with the given element Name
]
YD selector | Selects a single element which | $(#elementid’) |
| matches with the given ID
CLASS _| Selects all elements which matches | S(.class') SC-big)
selector with the given Class
Universal | Selects all elements available in the | S(™) sry
Selector __| document (DOM)
NOTE: Before you start creating jQuery codes, you must download the jQuery library from
the internet
ExampleS: This example uses ID selector to produce alert dialog box when a particular
element (button) is clicked.
ehead>
Eielesthe jquery Exanplec/titie>
aorcene/javaserspt: sece"/Jquery/jquery-2.3.2.ain.js"9
‘text/Javascript" languages" javascript">
cument).ready(funetion()
5S cocecamcne,weieeCcHEls0, this 45 JQuery DENO");
s("Hbtna").click(funetion() { :
alert("Hi, You clicked Button 11");
Ds .
ys
.
CBee eypeetsubmic” ide"vtns” values"Button 2">
Example 6: This example shows how form data ean be retrieved when submit button is
clicked, how to clear the form data.
1
~
Scanned with CamScannerATBU_OMS_¢5212 2019/25
!
citlestale setitio
script typee"ext/ javascript” srce"/Jquery/ jquery
Seripe typec"tert/Janscegt” lonpusdet eee se an rleetety |
S(document).ready(function() “
S(*asubeit_btn") clck(function() ( |
var user_nane © $("tusertiaze").val(); |
var pass_word = $("tpasshore").val(); |
var vs “Usernane"ouser-nose » "Pstivordi"4pess words
alert(v); 7
di:
S("#reset_btn").click(function() {
wae Gber_pane = d¢rnasertioe!
var pesscvord = S¢capasanors®
| Eceeierd «Freee |
van");
wal);
ns
Ds
| e
|
‘foray |
“text” See"useriiace”scbr>
|
+ input type:
= |
|
|
| -
ASYNCHRONOUS JAVASCRIPT and XML (AJAX)
up request-is sent to server and the s
owser) then reloads in order to displey
i ve ste
Traditionally, in web applications, erver prose
request accordingly and respond, The page (br.
response.
2
ry
Scanned with CamScannerATBU_DMS_cs212_2619/2020
technique that uses JavaScript and XM
IL call is
whenever http request is sent to sever, AJAX is used to prevent reloading of page
AJAX, which stands for Async and XML, set of techniques for
‘synchronous JavaScript and XML, i iq
X, which s if onou » is a set of techni
creating highly interactive web applications. The idea is to make what's on the Web ae to
be local by giving a rich user experience, and offeri in
; wee » and offering features that usually only appear i
Te emphasis i Ain eppliations is to update the web page, using data fetched from the
y reshing the web page in the bro. “ F
fess lines Canc india. ge rowser. The term “AJAX” was created by
AJAX uses JavaScript’s XMLHttpRequest method to exchange data with the server without
reloading the current page. AJAX technique offer the following advantages
* Itenables quick, small transactions
* Client can communicate more often with the server
* More flexible user-interfaces can be built
* Web applications can.look/act more like desktop apps
However, it has some disadvantages.
* Tough to make compatible across all browsers
+ Can be server intensive
‘Typical Ajax transaction looks like this
User triggers some event (eg, clicking a button.) which call a JavaScript function
(event handler) that will respond to the event,
Event handler code sends XMLHTTP request to server
Server replies triggering code on client
Reply handler code updates web page using server's reply. When the response arrives,
client handler does something. For example, update just a PART of the page.
Between steps 2 and 3 the web page is still usable (event is asynchronous). At no point during
the transaction does the browser open a new web page.
“The server's response can be in the following forms:
* Plain text
" Anamay
* JSON
AJAX can be used with ordinaryJavaScript and can equally be used with jQuery and eachis a
topic on its own. In fact, there are so many BOOKS written in this regard! You can explore
further please.
‘The following is an example of AJAX with plain JavaScript
13
Scanned with CamScannerATBU_DMS_¢S212 2019/2029
[rantmi>
ceitleoajax Example