Birla Institute of Technology & Science, Pilani: Work Integrated Learning Programmes
Birla Institute of Technology & Science, Pilani: Work Integrated Learning Programmes
Course Description
The course introduces technologies related to web development and associated technologies that
makes the web work. It introduces descriptive languages like HTML, CSS and the de facto scripting
language JavaScript which powers all dynamic websites today. Focus on both client and server-side
technologies is covered to provide an understanding of the full stack. Server administration topics
helps to understand how web applications are setup on server. Protocols that are used to exchange
information and various web information formats are also added. This helps to gain an
understanding of how web applications are designed and how to develop simple web applications
that could query database and fetch information over the network and debug the same.
Course Objectives
No Objective
CO1 Learn client side and server side technologies and associated components involved at both client
and server end.
CO2 Learn the structure of web page and how to design the same using HTML and CSS. Able to
understand and write client side scripts on a web page using JavaScript.
CO3 Understand 3-tier client-server architecture and learn how to develop simple web applications
with a web interface to accepts inputs and process them accordingly
CO4 Learn working of a web server and the corresponding administration for publishing and managing
web applications written in PHP.
Text Book(s)
No Author(s), Title, Edition, Publishing House
T1 Robert W. Sebesta, Programming the World Wide Web, 7th Ed, Pearson
PHP
http://php.net/manual/en/getting-started.php
Content Structure
No Title of the Module References
M1 Introduction to Web technologies: T1 - Chapter 1,
• What is Internet - History of the Internet and World Wide Web, World R1 - Chapter 2
Wide Web Consortium (W3C)
• Web Servers, Web browsers
• Addressing, IP Address, Domain names, DNS Lookup, Uniform
Resource Locator (URL), URL Paths
• Protocols - HTTP, HTTPS, FTP
• Web developer languages - HTML, CSS, XML, JavaScript, PHP
M2 HTML: T1 - Chapter 2,
• HTML and XHTML R1 - Chapter 4
• HTML Basics - Boilerplate HTML5 document and its structure
• HTML5 document structure and basic text mark up
• XHTML document validation
• Image formats and Image element
• Hypertext Links
• Lists
• Tables and Table sections
• Forms and Form elements - select, textarea, button, complete form
• meta elements
• HTML5 new Elements
• HTML5 Web APIs
M3 Cascading Style Sheets: T1 - Chapter 3,
• Level of style sheets, style specification formats R1 - Chapter 5
• Selector Forms - Simple, Class, Generic, id, Contextual, Pseudo,
Universal
• Property-value forms
• Font Properties
• List Properties
• Text Alignment
• Color
• Box Model and Text Flow
• Background images
• <span> and <div> tags
• Conflict resolution
M4 JavaScript Basics: T1 - Chanter 4,
• Overview of JavaScript and its uses R1 - Chapter 6,
• Object Orientation and JavaScript 7, 8, 9, 10, 11
• Primitives, Operations, and Expressions
• Screen output and Keyboard input
• Control statements
• Object creation and modification
• Arrays
• Functions
• Errors in Scripts
M5 JavaScript and Document Object Model: T1 - Chapter 5,
• The Document Object Model (DOM) R1 - Chapter 12,
• Element access 13
• Events and event handling
• Handling events - Body elements, button elements, textbox, password
• DOM 2 Event Model
• DOM Tree Traversal and Modification
• DOM Collections
• Dynamic Styles
M6 XML: T1 - Chapter 7,
• Syntax and XML document structure R1 - Chapter 14
• Document Type Definitions (DTD)
• Namespaces
• XML Schemas
M7 Web Servers: R1 - Chapter 21
• What are Web Servers - Introduction
• HTTP transactions
• Multitier Application Architecture
• Client-side Scripting versus Server-Side Scripting
• Accessing Web Servers
• Case Study 1 - Microsoft Internet Information Server (IIS)
• Case Study 2 - Apache HTTP Server
M8 Server Side Scripting with PHP: T1 - Chapter 9,
• General Syntactic Characteristics R1 - Chapter 23
• Primitives, Operations, and Expressions, Outputs
• Control Statements
• Arrays
• Functions
• Form handling, Form Processing and Business Logic
• Connecting to Database
• Dynamic Content
Learning Outcomes:
No Learning Outcomes
LO1 Demonstrate how to develop a simple web pages using HTML and CSS and JavaScript to
accepts user inputs and validate them at client side using JavaScript.
LO2 Develop simple web applications using PHP to receive inputs from client side and able to
fetch information from backend e.g. database.
LO3 Understand how to setup a web server, publish a web application and manage it.
LO4 Understand server side logs and how to debug simple web applications and rectify the
problems in them.
Detailed Structure
Introductory Video/Document: << Introducing the faculty, overview of the course, structure and
organization of topics, guidance for navigating the content, and expectations from students>>
Each of the sub-modules of Recorded Lectures (indicated by RLx.y / LS x.y / LSx.yVz) shall
delivered via 30 – 60mins videos followed by:
Contact session (CSx.y) of 2Hr each for illustrating the concepts discussed in the videos with
exercises, tutorials and discussion on case-problems (wherever appropriate); contact sessions (CS)
may cover more than one recorded-lecture (RL) videos.
Course Contents
<From content structure in Part A of this document. Detail the plan of delivery across each contact
hour or each contact session. 1 contact session = 2 contact hours>
Post- HW/Lab
CH/CS
Lab Lab Capsule 8.2 Module 8.2 Lab Sheet- Database connection using PHP
Reference
CS10 : Review Session
Lab Details
Lab No Lab Objective Lab Sheet/Capsule Content Reference
Access URL
1 To understand the HTTP T1 - Chapter 1,
request and Response R1 - Chapter 2
Select Topics and Case Studies from business for experiential learning
2 Create cascading styles styles and apply them to the HTML pages T1, R1
designed above.
5 Exercises using PHP to process server side logic and connect and T1, R1
fetch database contents.
Evaluation Scheme
Legend: EC = Evaluation Component
No Name Type Duration Weight Day, Date, Session, Time
EC-1 Quiz-I Online - 5% August 23 – September 01,
2019
Quiz-II Online 5% September 27 – October 6,
2019
Assignment-I Online 15% November 01 – 10, 2019
EC-2 Mid-Semester Test Closed Book 2 hours 30% Sunday, 22/09/2019 (FN)
10 AM – 12 Noon
EC-3 Comprehensive Open Book 3 hours 45% Sunday, 17/11/2019 (FN)
Exam 9 AM – 12 Noon
Mid-Semester Test
(EC-2 Regular)
Q.1) A web browser at a client accesses a static HTML webpage from a web server S. The HTML
page contains exactly one static image which is also at S. Assuming no caching, how many HTTP
requests needs to be sent from the client to web server S to load the HTML page? Explain your
answer [2]
Q.2) A user request for a web page at a URL, but the page is no longer available at the indicated
URL. What will be the web server’s HTTP response? Can the web browser automatically download
the right web page from the new URL? [3]
Q.3) i) What is the purpose of HTTP TRACE method? How will the web server respond to a HTTP
TRACE Request? [3]
ii) Which HTTP method is suitable for obtaining Meta information about the web page without
transferring the HTML contents? How it will be useful? [2]
Q.4) Create an HTML page which contains the following definition list. [3]
HTTP
HyperText Transfer Protocol
FTP
File Transfer Protocol
SMTP
Simple Mail Transfer Protocol
POP
Post Office Protocol
Q.5) What is the use of preload attribute in the HTML video element? What are the attribute
values it can have? [3]
Q.6) If your CSS doesn't set the width and height of an element, how is the width and height of that
element determined? [2]
Q.7) Explain the difference between a CSS position of fixed and absolute. [2]
Q.8) Is it possible to change the transparency of an element's background without affecting the child
elements using the opacity property? If yes, mention how it can be done. If no, suggest alternate method to
do the same [3]
Q.9) What does the following JavaScript print in the console? [3]
var x=1;
(function(x){
console.log(x);
x=3;
})(2);
console.log(x);
Q.10) Write a JavaScript program to display the current day and time in a webpage. [4]
******************
Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
Second Semester 2018-2019
Mid-Semester Test (EC-2 Regular)
Q.2. Explain about the information sent in the ‘Client Hello’ message in a TLS handshake? [2]
Q.4. The anchor <a> tag in HTML supports an attribute named target. For example, a link to the
Google search page could be written as:
<a target=”_blank” href=http://www.google.com>Google</a>
What is the purpose of the target attribute? What will be the change in the behavior, if the
target attribute takes the values _self, _blank, _top and _parent? [3]
Q.5. What is the use of a novalidate attribute and autocomplete attribute for the form tag that was
introduced in HTML5? [2]
Q.6. Write a HTML code to create a form exactly as shown below. The form contains one drop
down menu, one date selector along with send and reset buttons. [5]
Q.7. How will the total width and total height of an element be calculated according to the box
model? Calculate the total width and height of the div element with the following CSS code
[2]
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
Q.8. Q.8.
<html>
<body>
<div id="div1">Web</div>
<div id="div2" class="class1">BITS-Pilani</div>
<div>
<span id="span1" class="class1">WILP</span>
<span id="span2" class="class2">Exam</span>
</div>
</body>
</html>
Illustrate what will be the changes in text color for the words (Web, BITS-Pilani, WILP,
Exam) in the above HTML page, when the following CSS rules are applied. [4]
i. div { color: red}
div.class1 {color: green}
ii. #span2 {color: yello}
Q.9. What will be the output of the javascript code below? [2]
Q.10. What will be the output of the javascript code below? [2]
**********
Learn client side and server side technologies and associated components involved at both client and
server end.
Learn the structure of web page and how to design the same using HTML and CSS. Able to understand
and write client side scripts on a web page using JavaScript.
Understand 3-tier client-server architecture and learn how to develop simple web applications with a web
interface to accepts inputs and process them accordingly
Learn working of a web server and the corresponding administration for publishing and managing web
applications written in PHP.
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Readings
CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
19/07/2019
Course Overview
XML
Web Servers
Server Side Scripting
• PHP
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Client –Server Architecture
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Three essential technologies of Web
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Working of the Web
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
URL (Uniform Resource Locator)
11
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Parts of a URL
PORT NUMBER
The default port number of HTTP is 80.
If a server has been configured to use some other port number, it is necessary
to attach that port number to the hostname in the URL.
Example : www.bits-pilani.ac.in:8080
Path-and-file-name
The name and location of the requested resource, under the server document
base directory.
The location is typically a virtual directory.
Server maps requested URLs to the document, whose location is not known to
clients.
URLs cannot include spaces. 12
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Parts of a URL
A query string.
If a query string is used provides a string of information that the resource can
use.
The query string is usually a string of name and value pairs;
for example, term=btech.
Name and value pairs are separated from each other by an ampersand (&);
for example, term=btech&course=cse.
Fragment
The fragment is used to refer to an internal section within a web document.
13
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
For example,
http://www.bits-pilani.ac.in:8080/admissions/firstdegree?term=btech#h1
Communication protocol:http
Hostname: bits-pilani.ac.in
Portnumber:8080
Path: /admissions/firstdegree
Query string: term=btech
Fragment=h1
The document root in web server is :/admin/web/topdocs.
http://www.bits-pilani.ac.in:8080/admissions/firstdegree
file path /admin/web/topdocs/admissions/firstdegree 14
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
15
19/07/2019
HyperText Transfer Protocol(HTTP)
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP(Contd…)
17
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Request
18
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Request
19
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Request Line
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Request Headers
The request headers are in the form of name:value pairs. Multiple values,
separated by commas, can be specified.
21
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Response
The status line includes the HTTP version used, a three-digit status code for the
response, and a short textual explanation of the status code.
22
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Response
23
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Status Line
Status code is a three-digit number; first digit the specifies the general status
1 => Informational
2 => Success
3 => Redirection
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Response Headers
Content-Type: text/html
Content-Length: 35
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
The response message body contains the resource data requested.
26
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Methods
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
GET Method
29
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
say=Hi&to=John
30
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HEAD Method
The HEAD method asks for a response identical to that of a GET request, but
without the response body.
The server replies with a response line and headers, but no entity-body
HEAD /hello.htm HTTP/1.1 HTTP/1.1 200 OK
Date: Mon, 27 Jul 2018 12:28:53 GMT
User-Agent: Mozilla/4.0
Server: Apache/2.2.14 (Win32)
Host: www.google.com Last-Modified: Wed, 22 Jul 2019 19:15:56 GMT
Accept-Language: en-us ETag: "34aa387-d-1568eb00"
Accept-Ranges: bytes
Accept-Encoding: gzip, deflate Content-Length: 88
Connection: Keep-Alive Content-Type: text/html
HEAD request is useful for checking the headers, such as Last-Modified,
Content-Type, Content-Length, before sending a proper GET request to
retrieve the document.
31
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
PUT METHOD
The PUT method is used to request the server to store the included entity-body
at a location specified by the given URL.
The PUT method replaces all current representations of the target resource with
the request payload.
PUT /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.google.com
Content-type: text/html
Content-Length: 182
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html> 32
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
OPTIONS METHOD
The OPTIONS method is used to describe the communication options for the
target resource.
The OPTIONS method is used to find out the HTTP methods supported by a
web server.
The client can specify a URL for the OPTIONS method,
An asterisk (*) to refer to the entire server.
OPTIONS * HTTP/1.1
User-Agent: Mozilla/4.0
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2018 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Type:text/html 33
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DELETE METHOD
The web servers do not enable delete method for all users
34
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CONNECT METHOD
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TRACE METHOD
The TRACE method performs a message loop-back test along the path to the
target resource.
The contents of an HTTP Request is echoed back to the requester
HTTP/1.1 200 OK
It can be used for debugging purposes. Date: Mon, 27 Jul 2018 12:28:53 GMT
TRACE / HTTP/1.1 Server: Apache/2.2.14 (Win32)
Connection: close
Host: www.google.com
Content-Type: message/http
User-Agent: Mozilla/4.0 Content-Length: 39
TRACE / HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/4.0
36
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Methods
Some of the methods (for example, HEAD, GET, OPTIONS and TRACE) are,
by convention, defined as safe.
Methods PUT and DELETE are defined to be idempotent
The POST method is not idempotent.
Sending an identical POST request multiple times may further affect state
Web Browsers show dialog boxes to warn users
37
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example 1 Misspelt Request Method
38
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example 2 : Accessing a Protected Resource
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Headers –Caching-ETAG
The ETag HTTP response header is an identifier for a specific version of a resource.
If the resource at a given URL changes, a new Etag value must be generated.
ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4“
The client will send the Etag value of its cached resource along in an If-None-Match header field:
If-None-Match: "33a64df551425fcc55e4d42a148795d9f25f89d4“
The server compares the client's ETag (sent with If-None-Match) with the ETag for its current version of the
resource
If both values match, the server send back a 304 Not Modified status, without any body
Tells the client that the cached version of the response is still good.
40
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Last-Modified Header
The Last-Modified response HTTP header contains the date and time at which
the origin server believes the resource was last modified.
It is used as a validator to determine if a resource received or stored is the
same.
Less accurate than an ETag header
41
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Headers- Connection Management
Connection Header
The Connection general header controls whether or not the network connection
stays open after the current transaction finishes.
If the value sent is keep-alive, the connection is persistent and not closed,
allowing for subsequent requests to the same server to be done.
Connection: keep-alive
Connection: close
Keep-alive Header
The Keep-Alive general header allows the sender to hint about how the
connection may be used to set a timeout and a maximum amount of
requests.
Keep-Alive: timeout=5, max=1000
42
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Redirection
43
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTP Headers-Cookies
An HTTP cookie is a small piece of data that a server sends to the user's web
browser.
The browser may store it and send it back with the next request to the same
server.
The Set-Cookie HTTP response header sends cookies from the server to the
user agent.
Set-Cookie: <cookie-name>=<cookie-value>
The Cookie HTTP request header contains stored HTTP cookies previously
sent by the server with the Set-Cookie header.
Cookie: name=value; name2=value2; name3=value3
44
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
MIME
45
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Questions?
B) HTTP vs HTTPS?
46
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
Lecture 2: HTTPS
HTTPS (Hypertext Transfer Protocol
Secure)
• Hypertext Transfer Protocol Secure is a secure version of HTTP.
• This protocol enables secure communication between a client (e.g. web
browser) and a server (e.g. web server) by using encryption.
• HTTPS uses Transport Layer Security (TLS) protocol or its
predecessor Secure Sockets Layer (SSL) for encryption.
• HTTPS is commonly used to create a secure channel over some insecure
network, e.g. Internet.
• HTTPS URLs begin with https instead of http.
• HTTPS uses a well-known TCP port 443.
48
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTTPS
The Transport Layer Security (TLS), and Secure Socket Layer (SSL) protocols’
main purpose is to provide
• Privacy and Integrity
• Identification and Authentication
• SSL/TLS protocol can be used in different services such as web, mail, FTP,
VoIP and VPN.
• Typically, when a service uses a secure connection the letter S is appended
to the service’s protocol name.
• For example: HTTPS, SMTPS, FTPS, SIPS.
49
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Encryption
• Symmetric Encryption
• Symmetric encryption is the process in which the same key is used for
encrypting and decrypting data.
50
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Certificates
When a secure connection is established, the server will send its TLS/SSL
certificate to the client.
The certificate will then be checked by the client against a trusted Certificate
Authority, essentially validating the server’s identity.
A TLS/SSL certificate essentially binds an identity to a pair of keys which are
then used by the server to encrypt as well as sign the data.
A Certificate Authority is an entity which issues TLS/SSL or Digital certificates.
51
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Certificate Authority
52
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TLS handshake
The SSL or TLS handshake enables the SSL or TLS client and server to
establish the secret keys with which they communicate.
• Agree on the version of the protocol to use.
• Select cryptographic algorithms.
• Authenticate each other by exchanging and validating digital certificates.
• Use asymmetric encryption techniques to generate a shared secret key,
which avoids the key distribution problem.
• SSL or TLS then uses the shared key for the symmetric encryption of
messages, which is faster than asymmetric encryption.
53
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The TLS Handshake Protocol
54
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The TLS Handshake Protocol
• The client sends a "Client hello" message to the server, along with the
client's random value and supported cipher suites.
• The server responds by sending a "Server hello" message to the client,
along with the server's random value.
• The server sends its certificate to the client for authentication and may
request a certificate from the client.
• The server sends the "Server hello done" message.
• If the server has requested a certificate from the client, the client sends it.
• The client creates a random Pre-Master Secret and encrypts it with
the public key from the server's certificate, sending the encrypted Pre-
Master Secret to the server.
55
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The TLS Handshake Protocol
• The server and client each generate the Master Secret and session
keys based on the Pre-Master Secret.
• The client sends "Change cipher spec" notification to server to indicate that
the client will start using the new session keys for hashing and encrypting
messages. Client also sends "Client finished" message.
• Server receives "Change cipher spec" and switches its record layer security
state to symmetric encryption using the session keys.
• Server sends "Server finished" message to the client.
• Client and server can now exchange application data over the secured
channel they have established.
• All messages sent from client to server and from server to client are
encrypted using session key. 56
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TLS Record Protocol
The Transport Layer Security (TLS) Record protocol secures application data
using the keys created during the Handshake.
The Record Protocol is responsible for securing application data and verifying
its integrity and origin.
Dividing outgoing messages into manageable blocks, and reassembling
incoming messages.
Compressing outgoing blocks and decompressing incoming blocks (optional).
Encrypting outgoing messages and decrypting incoming messages.
When the Record Protocol is complete, the outgoing encrypted data is passed
down to the Transmission Control Protocol (TCP) layer for transport.
57
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Problems with HTTPS
Mixed content occurs when initial HTML is loaded over a secure HTTPS
connection, but other resources (such as images, videos, stylesheets,
scripts) are loaded over an insecure HTTP connection.
Modern browsers display warnings about this type of content to indicate to the
user that this page contains insecure resources.
Invalid Certificates
Semantic attacks: Extended Validation Certificate
58
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Demos
Certificates in browser
Using Curl
curl is a tool to transfer data from or to a server, using one of the
supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP,
DICT, TELNET, LDAP or FILE).
59
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DNS
The Domain Name System resolves the names of internet sites with their
underlying IP addresses.
A DNS server is a computer server that contains a database of public IP
addresses and their associated hostnames
DNS is a distributed database implemented in a hierarchy of name servers.
It is an application layer protocol for message exchange between clients and
servers.
60
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DNS
DNS record – Domain name, ip address , validity, all the information related to
that domain name.
These records are stored in tree like structure.
61
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DNS
The DNS cache attempts to speed up the process even more by handling the
name resolution of recently visited addresses before the request is sent out
to the internet
62
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Record Types
63
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CORS
64
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The HTTP headers that relate to CORS
Request headers
Origin
Access-Control-Request-Method
Access-Control-Request-Headers
Response headers
Access-Control-Allow-Origin
Access-Control-Allow-Credentials
Access-Control-Expose-Headers
Access-Control-Max-Age
Access-Control-Allow-Methods
Access-Control-Allow-Headers 65
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
MIME
MIME types enable browsers to recognize the filetype of a file which has been
sent via HTTP by the webserver.
MIME (Multi-purpose Internet Mail Extensions) is an expansion of the original
Internet e-mail protocol that exchanges different kinds of data files on the
Internet: text, audio, video, images, application programs, and others.
66
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
MIME Types
67
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Summary of Module 1
URL
HTTP
HTTP Methods
HTTP Request and Response
HTTPS
DNS
68
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Questions?
A) HTTP vs HTTPS?
69
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
References
1) Robert W. Sebesta, Programming the World Wide Web, 7th Ed, Pearson
2) Mozilla Developer Network
70
19/07/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
THANK YOU
71
19/07/2019
CSI ZG526 Web Technologies
I Sem 2018-19
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
SAMPLE HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Basic HTML Document Layout</title>
</head>
<body>
<h1>My First Web Page</h1>
<hr>
<p>This is my <strong>first</strong> web page written in HTML.</p>
<h3>HTML</h3>
<p>HTML uses <em>markup tag</em> to <em>markup</em> a document.</p>
</body>
</html>
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BASIC TAGS
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Links and Images
HTML Images
<img src=“BITS.jpg" alt=“BITS-pilani.com" width="104" height="142">
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
LISTS
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTML ATTRIBUTES
Attributes, in the form of name="value" pairs can be included in the opening tag to provide additional
information about the element.
Example 1: In <html lang="en">, the attribute lang="en" specifies the natural language for this document.
Example 2: In <meta charset="utf-8">, the attribute charset="utf-8" specifies the character encoding
scheme.
Example 3: An <img> (image) tag may contain these attributes:
<img src="logo.gif" alt="logo" width="50" height="30" />
The attribute "src" specifies the source-URL of the image; "alt" specifies an alternate text, if the image
cannot be displayed; "width" and "height" specify the width and height of the image displayed area.
Some of the attributes are mandatory (e.g., the "src" and "alt" attributes of the <img> tag); while some are
optional
Multiple attributes are separated by space, as follows:
<tag-name attName1="attValue1" attName2="attValue2" ...> ... </tag-name>
8
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Special Characters
Character Entity Reference
" "
< <
> >
& &
non-breaking space
→⇒↔⇔ → ⇒ ↔ ⇔
° (degree) °
©®€¢¥ © ® € ¢ ¥
˜ ˜
×±∞ × ± ∞
πΠσΣωΩ π Π σ Σ ω Ω
≥≤≡≈ ≥ ≤ ≡ ≈
⊂⊃⊆⊇∈ ⊂ ⊃ ⊆ ⊇ ∈
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TABLES
Tables
The basic unit of a table is a cell. Cells are grouped into row. Rows are grouped to form the table. This
corresponds well to the "row-centric" approach in the display.
<table>...</table>: contains the entire table.
<tr>...</tr>: contains a row.
<th>...</th> and <td>...</td>: contain a header cell and a data (detail) cell respectively.
10
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Tracking Document Changes
The del element is used to mark up text that has been deleted from a
document. It is useful if you want the original text to remain to provide a
record of changes to the document over time.
There are two attributes that can be used to provide additional information
about the reason a change was made to a document.
cite can be used to add a URL that further explains the reason for the change.
datetime can be used to specify the time when the change was made.
11
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The <form> tag
The <form arguments> ... </form> tag encloses form elements (and probably other HTML as well)
– action="url" (required)
• Specifies where to send the data when the Submit button is clicked
– method="get" (default)
• Form data is sent as a URL with ?form_data info appended to the end
• Can be used only if data is all ASCII and not more than 100 characters
– method="post"
• Form data is sent in the body of the URL request
• Cannot be bookmarked by most browsers
– target="target"
• Tells where to open the page sent as a result of the request
• target= _blank means open in a new window
• target= _top means use the same window
12
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The <input> tag
Most, but not all, form elements use the input tag, with a type="..." argument to
tell which kind of element it is
– type can be text, checkbox, radio, password, hidden, submit, reset, button, file, or
image
Other common input tag arguments include:
– name: the name of the element
– value: the “value” of the element; used in different ways for different values of type
– readonly: the value cannot be changed
– disabled: the user can’t do anything with this element
– Other arguments are defined for the input tag but have meaning only for certain values of
type
13
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A complete example
<html>
<head>
<title>Get Identity</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<p><b>Who are you?</b></p>
<form method="post" action="">
<p>Name:
<input type="text" name="textfield">
</p>
<p>Gender:
<input type="radio" name="gender" value="m">Male
<input type="radio" name="gender" value="f">Female</p>
</form>
</body>
</html> 14
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
New HTML5 input Types
Many web sites contain HTML code like: <div id="nav"> <div class="header"> <div id="footer">
to indicate navigation, header, and footer.
HTML5 offers new semantic elements to define different parts of a web page:
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary> 16
<time> CSIZG526 Web Technologies
03/08/2019 BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Metadata: the <meta> element
17
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Viewport attribute for meta element
• You should include the following <meta> viewport element in all your web
pages:
• <meta name="viewport" content="width=device-width, initial-scale=1.0">
• A <meta> viewport element gives the browser instructions on how to control
the page's dimensions and scaling.
• The width=device-width part sets the width of the page to follow the screen-
width of the device (which will vary depending on the device).
• The initial-scale=1.0 part sets the initial zoom level when the page is first
loaded by the browser.
18
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
.
HTML5 Attributes
content text Gives the value associated with the http-equiv or name attribute
http-equiv content-type Provides an HTTP header for the information/value of the content
default-style attribute
refresh
name application-name Specifies a name for the metadata
author
description
keywords
viewport
19
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Examples
20
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Other type of Meta Element
For example, Open Graph Data is a metadata protocol that Facebook invented to provide richer
metadata for websites. In the MDN sourcecode, you'll find this:
<meta property="og:image" content="https://developer.cdn.mozilla.net/static/img/opengraph-
logo.dc4e08e2f6af.png">
<meta property="og:description" content="The Mozilla Developer Network (MDN) provides
information about Open Web technologies including HTML, CSS, and APIs for both Web sites
and HTML5 Apps. It also documents Mozilla products, like Firefox OS.">
<meta property="og:title" content="Mozilla Developer Network">
One effect of this is that when you link to MDN on facebook, the link appears along with an
image and description: a richer experience for users.
21
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DIV and SPAN
22
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The <video> element
23
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Video elemet
preload
this attribute is used in the element for buffering large files. It can take one of 3 values:
– "none" does not buffer the file
– "auto" buffers the media file
– "metadata" buffers only the metadata for the file
24
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The <audio> element
The <audio> element works in exactly the same way as the <video> element
<audio controls>
<source src="viper.mp3" type="audio/mp3">
<source src="viper.ogg" type="audio/ogg">
<p>Your browser doesn't support HTML5 audio. Here is a <a href="viper.mp3">link to the
audio</a> instead.</p>
</audio>
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The <track> element
HTML5 allows us to specify subtitles for a video using the <track> element.
Web Video Text Tracks Format (WebVTT) is a format for displaying timed text tracks (such as
subtitles or captions) using the <track> element.
The primary purpose of WebVTT files is to add text overlays to a <video>.
WebVTT is a text based format, which must be encoded using UTF-8.
<video id="video" controls preload="metadata">
<source src="video/sintel-short.mp4" type="video/mp4">
<source src="video/sintel-short.webm" type="video/webm">
<track label="English" kind="subtitles" srclang="en" src="captions/vtt/sintel-en.vtt" default>
<track label="Deutsch" kind="subtitles" srclang="de" src="captions/vtt/sintel-de.vtt">
<track label="Español" kind="subtitles" srclang="es" src="captions/vtt/sintel-es.vtt">
</video>
26
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Inline frame
27
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Figure Element
28
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTML Graphics
HTML5 SVG
SVG stands for Scalable Vector Graphics
SVG is used to define graphics for the Web
The HTML <svg> element is a container for SVG graphics.
SVG has several methods for drawing paths, boxes, circles, text, and graphic images.
HTML Canvas
The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript.
The <canvas> element is only a container for graphics. You must use JavaScript to actually
draw the graphics.
Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
29
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Difference between Canvas and SVG
Canvas SVG
30
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTML and debugging
• HTML is not compiled into a different form before the browser parses it and shows the result
(it is interpreted, not compiled).
• The way that browsers parse HTML is a lot more permissive than how programming
languages are run
• There are two main types of error
• Syntax errors: These are spelling errors in your code that actually cause the program not to
run. Logic errors: These are errors where the syntax is actually correct, but the code is not
what you intended.
• HTML itself doesn't suffer from syntax errors because browsers parse it permissively,
meaning that the page still displays even if there are syntax errors.
31
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Some new Features of HTML5
• Geolocation
– Get user position, GPS
• WebStorage
– Instead of cookies
• Indexed DB
• Web Workers
– : Certain web applications use heavy scripts to perform functions. Web Workers use separate background
threads for processing and it does not effect the performance of a web page.
32
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTML Boilerplate
• The underlying foundations of the vast majority of websites are very similar.
• Boilerplates are similar to templates,
• They contain text and graphics to start you off rather than just layouts for
these elements.
• An HTML boilerplate is a set of files that you can download, which provide a
foundation for any website you create.
• Boilerplates may contain a range of file types, including HTML documents,
but also add CSS, JavaScript, placeholder images
• HTML5 Boilerpate is the self-described "web's most popular front-end
template
• Alternatives: Bootstrap, Web Starter Kit and Skeleton
• WIX, Wordpress etc., 33
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Q&A
What happens if you view a new HTML5 form input type in an older browser?
Which is the most accurate way for Geolocation to get a user’s position?
Which HTML5 element/tag would you use to define a footer?
Which of these did we not use and are no longer valid in HTML5?
Frame
Embed
Align
div
34
03/08/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
Thank You
CSI ZG526 Web Technologies
I Sem 2019-20
Module 3: CSS
2
What is CSS
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
An CSS example
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
How does CSS actually work?
When a browser displays a document, it must combine the document's content with its style
information. It processes the document in two stages:
1. The browser converts HTML and CSS into the DOM (Document Object Model). The DOM
represents the document in the computer's memory. It combines the document's content
with its style.
2. The browser displays the contents of the DOM.
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Document Object Model (DOM)
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
External StyleSheet
An external stylesheet is when you have your CSS written in a separate file with
a .css extension,
Reference it from an HTML <link> element.
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Internal StyleSheet
An internal stylesheet is place your CSS inside a <style> element, contained inside the HTML
head.
<html>
<head>
<title>My CSS experiment</title>
<style>
h1 {
color: blue;
background-color: yellow;
}
p {
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This is my first CSS example</p>
9
</body>
</html>
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Inline styles
Inline styles are CSS declarations that affect one element only, contained within a style attribute
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My CSS experiment</title>
</head>
<body>
<h1 style="color: blue;background-color: yellow;border: 1px solid black;">Hello World!</h1>
<p style="color:red;">This is my first CSS example</p>
</body>
</html>
Used in very restrictive environments
10
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CSS Syntax
11
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CSS Declarations
background-color: yellow;
There are more than 300 different properties in CSS and nearly an
infinite number of different values.
Not all pairs of properties and values are allowed; each property has a specific
list of valid values defined for it.
If a property is unknown or if a value is not valid for a given property, the
declaration is invalid and is ignored by the browser.
NOTE:
In CSS (and other web standards), US spelling has been agreed on as the
standard to stick to where uncertainty arises. For example, color (as seen in the
above code) should always be spelt color. colour won't work. 12
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CSS declaration blocks
{
colour: blue;
background-color: yellow;
border: 1px solid black;
}
13
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CSS selectors and rules
How to tell our declaration blocks which elements they should be applied to?
• This is done by prefixing each declaration block with a selector —
• A pattern that matches some elements on the page. The associated declarations will be
applied to those elements only.
• The selector plus the declaration block is called a ruleset, or often simply just a rule.
• A rule match multiple elements by including multiple selectors separated by commas (a
group,) and selectors can be chained
h1 , h2, p{
colour: blue;
background-color: yellow;
border: 1px solid black;
}
14
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
COLORS
• Colors are specified using predefined color names, or RGB, HEX, HSL,
RGBA, HSLA values.
• RGB Colors
• RGB color values are supported in all browsers.
• An RGB color value is specified with: rgb(red, green, blue).
• Each parameter (red, green, and blue) defines the intensity of the color as an
integer between 0 and 255.
• For example, rgb(0, 0, 255) is rendered as blue, because the blue parameter
is set to its highest value (255) and the others are set to 0.
• background-color: rgb(0, 191, 255);
15
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
COLORS
• Hexadecimal Colors
• Hexadecimal color values are also supported in all browsers.
• A hexadecimal color is specified with: #RRGGBB.
• RR (red), GG (green) and BB (blue) are hexadecimal integers between 00
and FF specifying the intensity of the color.
• For example, #0000FF is displayed as blue, because the blue component is
set to its highest value (FF) and the others are set to 00.
16
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
COLORS
• Saturation
• Saturation is a percentage value; 0% means a shade of gray and 100% is the full color.
• Lightness
• Lightness is also a percentage; 0% is black, 100% is white.
• background-color: hsl(180, 50%, 50%);
17
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
COLORS
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Font Properties
font-family
– Value is a list of font names - browser uses the first in the list it has
font-size
– Possible values: a length number or a name, such as smaller, xx-large, etc.
font-style
– italic, oblique (useless), normal
font-weight - degrees of boldness
– bolder, lighter, bold, normal
font - for specifying a list of font properties
– font: bolder 14pt Arial Helvetica
– Order must be: style, weight, size, font name(s)
19
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
List Properties
20
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Background Images
21
10/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
Thank You
CSI ZG526 Web Technologies
I Sem 2019-20
2
What is the Box Model?
The box model is a tool we use to understand how our content
will be displayed on a web page.
Each HTML element appearing on our page takes up a "box" or
"container" of space.
Each box size is affected not only by content but also by padding,
borders, and margins.
By knowing how to calculate the dimensions of each box, we can
accurately predict how elements will lay out on the screen.
As we build a new page, we can arrange these boxes on the screen,
creating a balanced layout with white space around the content.
<style type="text/css">
.box200 {
width: 200px;
height: 200px;
border: 1px solid black;
color: blue;
padding: 10px;
margin: 10px;
}
</style>
...
The 10 pixel padding adds buffer space, on all four sides, between the
content and border. The 10 pixel margin adds buffer space, on all four
sides, between the border and surrounding elements.
CSI ZG526 Web Technologies
Padding and Margin Illustrated
The dotted red line
shows the margin's
outer boundary and the
dotted green line
shows the padding's
inner boundary.
242px When we define the
high width and height of a
<div> element, these
dimensions apply only
to the actual content,
not to the padding,
border, or margin.
242px CSI ZG526 Web Technologies
wide
Calculating Total Dimensions
When we are planning our page, we have to calculate exactly how much screen
space a <div> or any other element will use. The formula is:
Total element width = defined width + left padding + right padding + left
border + right border + left margin + right margin.
Total element height = defined height + top padding + bottom padding + top
border + bottom border + top margin + bottom margin.
If the three border properties will be identical on all four sides, we can use a
single-line border shorthand, as we did in an earlier lesson:
border: 5px solid blue;
<style type="text/css">
.box200 {
width: 200px;
height: 200px;
color: blue;
padding: 40px 10px 0px 10px;
margin: 25px 5px;
border-width: 2px 5px;
border-style: solid dotted;
border-color: red blue green maroon;
}
</style>
Boxes whose width will always shift to be a certain percentage of their parent container's width
20
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
CSS Font Properties
All CSS length values except 0 need units
Computed value
of font-size
property
– Absolute size keyword: xx-small, x-small, small, medium (initial value), large,
x-large, xx-large
• User agent specific; should differ by ~ 20%
– Relative size keyword: smaller, larger
• Relative to parent element’s font
27
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Positioning
• Position: static
• Position: relative
– By default, if you set the position property to relative, the element is placed as if it were static, but you can then
use the top, bottom, left and right property to move it around by setting these values relative to the original
position of element.
• Position: absolute
– An absolute positioned element is placed exactly where you want it to within the browser window, by adjusting
the top, bottom, left and/or right properties. This means that you can place elements e.g. in the top, right corner,
even if your main page has been tied to the middle of the screen.
• Position: fixed
– By using the fixed property, your element will be positioned as if it were absolute, with one very important
addition: When the user scrolls, the fixed element will remain in this position all the time. This allows you to
create, for instance, a top menu which remains on screen even when the user scrolls through down through
your page.
28
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The cascade
• Importance
• Specificity
• Source order
29
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Importance
• In CSS, the declaration which will always win over all others:
• !important.
• Conflicting declarations will be applied in the following order,
• The later ones overriding earlier ones.
• Declarations in user agent style sheets
• Normal declarations in user style sheets
• Normal declarations in author style sheets
• Important declarations in author style sheets
• Important declarations in user style sheets
30
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Specificity
31
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Specificity
The amount of specificity a selector has is measured using four different values.
thousands, hundreds, tens and ones — four single digits in four columns:
Thousands: Score one in this column if the declaration is inside a style attribute
– (such declarations don't have selectors, so their specificity is always simply 1000.) Otherwise 0.
Hundreds: Score one in this column for each ID selector contained inside the
overall selector.
Tens: Score one in this column for each class selector, attribute selector, or
pseudo-class contained inside the overall selector.
Ones: Score one in this column for each element selector or pseudo-element
contained inside the overall selector.
32
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Specificity
33
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Source order
When several CSS rules match the same element, they are all applied to that element. Only
after that are any conflicting properties evaluated to see which individual styles will win over
others.
<p>I'm <strong>important</strong></p>
/* specificity: 0002 */ I'm important
p strong {
background-color: khaki;
color: green;
}
/* specificity: 0001 */
strong {
text-decoration: underline;
color: red;
} 35
16/02/2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
Thank You
CSI ZG526 Web Technologies
II Sem 2018-19
Lecture 6: Javascript
2
Client Side Scripting
CS380
CS380
CS380
CS380
USES OF JAVASCRIPT
– Transfer of some load from server to client
– User interactions through forms
– Events easily detected with JavaScript
– Create web pages , add content to web pages
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Origins of JavaScript
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
JavaScript and Java
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
JavaScript Execution
• When you load a web page in your browser, you are running your code (the
HTML, CSS, and JavaScript) inside an execution environment (the browser
tab).
• The JavaScript is executed by the browser's JavaScript engine, after the
HTML and CSS have been assembled and put together into a web page.
• This ensures that the structure and style of the page are already in place by
the time the JavaScript starts to run.
10
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
JavaScript Execution
• Example (Inline)
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can change HTML content.</p>
<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click
Me!</button>
</body>
</html>
11
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Adding JS(Internal)
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
External Script
• Example
• <script src="myScript.js"></script>
• You can place an external script reference in <head> or <body>
13
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Embedding in HTML docs
Either directly, as in
<script type = “text/javascript”>
-- JavaScript script –
</script>
Or indirectly, as a file specified in the src attribute of <script>, as in
<script type = “text/javascript”
src = “myScript.js”>
</script>
14
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Event-driven programming
JS
<button>Click me!</button>
HTML
CS380
<element attributes
onclick="function();">...
HTML
<button onclick="myFunction();">Click
me!</button>
CS380
HTML
CSI ZG526 Web Technologies 20
JavaScript Running Order
If you swapped the order of the first two lines of code, it would no longer work.
An error returned in the browser developer console
21
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Variables
22
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Variables and its Scope
23
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Variables
variables are declared with the var keyword (case sensitive)
types are not specified, but JS does have types ("loosely typed")
– Number, Boolean, String, Array, Object, Function, Null,
Undefined
– can find out a variable's type by calling typeof
JS
CS380
26
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Primitive Data types
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Number
28
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Numeric Operators
29
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Boolean, Null, Undefined
Boolean
A boolean represents only one of two values: true, or false. Think of a boolean as an on/off or a
yes/no switch.
var boo1 = true;
var boo2 = false;
Null
Null has one value: null. It is explicitly nothing.
var nothing = null;
The only Null value is null
Undefined
A variable that has no value is undefined.
var testVar;
console.log(testVar); // undefined
30
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Special values: null and undefined
undefined : has not been declared, does not
exist
null : exists, but was specifically assigned an
empty or null value var ned = null;
var benson = 9;
// at this point in the code,
// ned is null
// benson's 9
// caroline is undefined
JS
32
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Comments (same as Java)
identical to Java's comment syntax
recall: 4 comment syntaxes
– HTML: <!-- comment -->
– CSS/JS/PHP: /* comment */
– Java/JS/PHP: // comment
– PHP: # comment
// single-line comment
/* multi-line comment */
JS
CS380
JS
identical structure to Java's if/else statement
JavaScript allows almost anything as a condition
CS380
JS
Javascript detects that you are trying to access a property of a string primitive.
It creates a wrapper object String to wrap the original string primitive.
It accesses the length and toUpperCase on the wrapper object instead of the original primitive.
It discards the wrapper object, frees the memory and continues.
39
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Manually creating wrappers
• In the example above, JavaScript creates wrapper objects automatically under the hood. There is also
a way to create such objects explicitly.
• new Number(4)
• new String('Hi')
• new Boolean(true)
• These are not primitives anymore, but objects, which contain the primitive value and add some extra
goodies.
• typeof 4 //number
• typeof 'Hi' //string
• typeof true //boolean
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
Thank You
CSI ZG526 Web Technologies
II Sem 2018-19
Lecture 7: Javascript
2
Array
• An array is a single object that contains multiple values enclosed in square brackets and separated by
commas.
• var myNameArray = ['Chris', 'Bob', 'Jim'];
• var myNumberArray = [10,15,40];
• Once these arrays are defined, you can access each value by their location within the array.
• myNameArray[0]; // should return 'Chris'
• myNumberArray[2]; // should return 40
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Arrays
var name = []; // empty array
var name = [value, value, ..., value]; //
pre-filled
name[index] = value; // store element
5
String type
methods: charAt, charCodeAt, fromCharCode, indexOf,
lastIndexOf, replace, split, substring, toLowerCase,
toUpperCase
– charAt returns a one-letter String (there is no char type)
JS
CSI ZG526 Web Technologies 6
More about String
escape sequences behave as in Java: \' \" \& \n \t \\
converting between numbers and Strings:
var count = 10;
var s1 = "" + count; // "10"
var s2 = count + " bananas, ah ah ah!"; // "10
bananas, ah ah ah!"
JS
var firstLetter = s[0]; // fails in IE
var firstLetter = s.charAt(0); // does work
in IE
var lastLetter = s.charAt(s.length - 1);
JS
CS380
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Converting between Strings and Arrays
myArray.length;
myArray[0]; // the first item in the array
myArray[1]; // the second item in the array
myArray[myArray.length-1]; // the last item in the array
var myNewString = myArray.join(',');
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Functions
function hello() {
console.log(“Hi”);
}
hello();
11
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Function Expression:
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Functions with a variable number of
parameters
An array named "arguments" is created automatically in each function, it
contains all the call parameters of the function:
function f() {
return arguments;
}
f(); // returns []
f( 1, 2, 3, 4, true, 'Michel Buffa'); // returns [1, 2, 3, 4, true, "Michel Buffa"]
function sum(a, b) {
var c = a + b;
return c;
}
sum(1)
13
NaN is assigned to one of the parameters
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Objects
Accessing property:
objectName.property // person.age
or
objectName["property"] // person["age"]
14
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Creating Objects
• Using an object literal, you both define and create an object in one statement.
• An object literal is a list of name:value pairs (like age:50) inside curly braces {}.
• var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
• var person = {
• firstName:"John",
• lastName:"Doe",
• age:50,
• eyeColor:"blue"
• };
15
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Using the JavaScript Keyword new
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Creating Objects Using Constructors
• Objects of the same type are created by calling the constructor function with
the new keyword:
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
This Keyword
In JavaScript, the thing called this, is the object that "owns" the JavaScript code.
The value of this, when used in a function, is the object that "owns" the function.
18
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
References and objects
Unlike a pointer variable, which contains the actual address of an object within
the memory, a reference variable is an alias to a variable. This means that
when you modify a reference variable, the original variable is modified too.
This is because the two variables reference (i.e. point to) the same object.
If its value is a primitive value (number, string, or boolean), the variable contains
this value directly.
If its value is an object, the variable contains the memory address of the object.
JavaScript is a "pass by value" language, unlike some other languages, which
are "pass by reference" languages. This means that when you pass a
variable to a function as argument, the value of the variable is copied into the
argument.
19
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example 1
var x = 2; // the variable x contains the primitive data 2
var y = { a: 2 } // The variable y references the object {a: 2}
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example 2
var x = 2;
function sum(a, b) {
a = a + b;
return a;
}
sum(x, 3); // returns 5
x; // 2 <- but x equals 2
var obj = { x: 2 }
function add(a, b) {
a.x += b;
}
add(obj, 3);
obj.x; // 5 <- The referenced object is modified
21
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Objects in JavaScript
22
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
More on Arrays
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
More on Strings
var x = "John";
var y = new String("John");
// (x == y) is true because x and y have equal values
// (x === y) is false because x and y have different types (string and object)
String methods
Slice(), concat(), reverse(), indexOf(), substr()
24
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Comparing two objects
Comparing two objects will only return true if they point to the same object
Two objects of the same type, with the same property value, that look identical, will not be equal one to another
> var originalObject = {name:'Michel'};
25
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
valueOf and toString
There are some cases when you would rather need a primitive representation
of the object. Actually, javascript offers two methods for it which each object
inherits:
valueOf() returns primitive representation of the object
toString() returns string representation of the object
A good example can be Date. toString() returns a human-readable description of the date, while valueOf()
returns a number representing the date as the number of passed milliseconds since 1 January 1970
00:00:00 UTC and the date.
var date = new Date();
console.log(date.toString()); //Wed Jan 24 2018 14:12:07 GMT+0100 (Central Europe Standard Time)
console.log(date.valueOf()); //1516817671281
26
17/02/2019 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Popup boxes
alert("message"); // message
confirm("message"); // returns true or
false
prompt("message"); // returns user input
string
JS
Alert Box
alert(“The sum is:” + sum + ”\n");
Parameter is plain text, not HTML
Opens a dialog box which displays the parameter string and an OK button
It waits for the user to press the OK button
28
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dialog Boxes
Confirm
var question = confirm("Do you want to continue this
download?");
Opens a dialog box and displays the parameter and two buttons, OK and Cancel
Returns a Boolean value, depending on which button was pressed (it waits for one)
29
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dialog Boxes
Prompt
prompt("What is your name?", “ ");
– Opens a dialog box and displays its string parameter, along with a text box and two buttons,
OK and Cancel
– The second parameter is for a default response if the user presses OK without typing a
response in the text box (waits for OK)
30
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Date Object
31
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Math Object
• The math object provides you properties and methods for mathematical
constants and functions.
• The Math Object provides floor, round, max, min, trig functions, etc.
• e.g., Math.cos(x)
32
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Regular Expression Object
• A regular expression is an object that describes a pattern of characters.
• RegExp define methods that use regular expressions to perform powerful pattern-matching and search-and-replace
functions on text
• var pattern = new RegExp(pattern, attributes);
• Using test()
• The test() method is a RegExp expression method.
• It searches a string for a pattern, and returns true or false, depending on the result.
• var patt = /e/;
• patt.test("The best things in life are free!");
• Using exec()
• The exec() method is a RegExp expression method.
• It searches a string for a specified pattern, and returns the found text.
• If no match is found, it returns null.
• /e/.exec("The best things in life are free!");
33
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Regular Expression
Expression Description
[^0-9] Find any character NOT between the brackets (any non-digit)
34
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Error Handling in JS
35
23-02-2019 CSIZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DOM
• The Document Object Model (DOM) is a interface between HTML and Javascript
• It represents the webpage, programs can change the document structure, style, and content.
• The DOM represents the document as nodes and objects.
• A Web page is a document. This document can be either displayed in the browser window or
as the HTML source.
• The Document Object Model (DOM) represents that same document so it can be
manipulated.
• The DOM is an object-oriented representation of the web page, which can be modified with a
scripting language such as JavaScript.
• Different browsers have different implementations of the DOM, but every web browser uses
some document object model to make web pages accessible via JavaScript.
36
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DOM
• "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."
37
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
HTML DOM
• The HTML DOM is a standard object model and programming interface for HTML. It defines:
38
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DOM
<html>
<head>
<title>My title</title>
</head>
<body>
<a href=“link”>My Link</a>
<h1>My header</h1>
</body>
</html>
39
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Document Object
• Document.URL
• Document.body
• Document.links
• Document.head
40
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Use the document object to access
• document.querySelectorAll()
41
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DOM Nodes
• According to the W3C HTML DOM standard, everything in an HTML document is a node:
• New nodes can be created, and all nodes can be modified or deleted.
42
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DOM TREE
Picture Reference:W3Schools 43
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Element Access in JavaScript
44
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Element Access in JavaScript
2. Element names
– requires the element and all of its ancestors (except body) to have name
attributes
– Example:
<form name = "myForm" action = "">
<input type = "button" name = "pushMe">
</form>
– document.myForm.pushMe
45
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Element Access in JavaScript
46
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Element Access in JavaScript
Checkboxes and radio button have an implicit array, which has their name
<form id = "toppingGroup">
<input type = "checkbox" name = "toppings"
value = "olives" />
... <input type = "checkbox" name = "toppings"
value = "tomatoes" />
</form>
...
var numChecked = 0;
var dom = document.getElementById("toppingGroup");
for (index = 0; index < dom.toppings.length; index++)
if (dom.toppings[index].checked]
numChecked++;
47
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The HTMLCollection Object
• Example
• var x = document.getElementsByTagName("p");
• The elements in the collection can be accessed by an index number.
48
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
NodeList
• Some (older) browsers return a NodeList object instead of an HTMLCollection for methods like
getElementsByClassName().
49
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
DOM Manipulation
50
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Changing Style and class
Solution:
• we can define a CSS class and then toggle it on or off with JS. Using classlist
• var tag = document.getElementById("highlight");
• tag.classList.add("some-class");
• The classList property returns the class name(s) of an element.
• This property is useful to add, remove and toggle CSS classes on an element.
• The classList property is read-only, however, you can modify it by using the add() and
remove() methods.
51
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
changing the content of a tag
• Similar to textContent, except it returns a string of all the HTML contained in a given element
• var tag = document.querySelector("p");
• tag.innerHTML –new content
52
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Changing attributes
• Use getAttribute() and setAttribute() to read and write attributes like src or
href
• element.attribute = new value Change the attribute value of an HTML
element
• element.setAttribute(attribute, value) Change the attribute value of an HTML
element
53
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Navigating Between Nodes
<html>
<head> parentNode
<title>DOM Tutorial</title> childNodes[node
</head> number]
firstChild
<body> lastChild
<h1>DOM Lesson one</h1> nextSibling
<p>Hello world!</p> previousSibling
</body>
</html>
54
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
NODES
55
08/09/2018 CSI ZG526 Web Technologies BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Hyderabad Campus
Thank You
Birla Institute of Technology and Science, Pilani
Work Integrated Learning Programme
LAB HANDOUT
PART –A
Exercise 1
Objective:
To understand how HTTP request and Responses are sent between the client to
browser.
Explanation:
Recorded Demo 1: Demonstration of HTTP requests generated and response
received for a Website
Practice Exercises:
EXERCISE 2:
Objective:
To use the curl command to generate http request using various HTTP
Methods
Explanation:
cURL is a computer software project providing a library and command-line tool
for transferring data using various protocols.
The URL could itself refer to a web page, an image or a file. The client issues a
GET request to the server and receives the document it asked for. If you issue
the command line
curl https://www.google.com
you get a web page returned in your terminal window. The entire HTML
document that that URL holds.
All HTTP replies contain a set of response headers that are normally hidden, use
curl's --include (-i) option to display them as well as the rest of the document.
HEAD
You can ask the remote server for ONLY the headers by using the --head (-I)
option which will make curl issue a HEAD request.
The HEAD method is defined and made so that the server returns the headers
exactly the way it would do for a GET, but without a body. It means that you
may see a Content-Length: in the response headers, but there must not be an
actual body in the HEAD response.
If you use --data to POST to the URL, using multiple URLs means that you
send that same POST to all the given URLs.
When curl reaches the --next on the command line, it'll sort of reset the method
and the POST data and allow a new set.
Perhaps this is best shown with a few examples. To send first a HEAD and then
a GET:
Practice Exercise:
Objective:
To analyse the HTTP and HTTPs packets using Wireshark.
Explanation:
Wireshark is a free and open-source packet analyzer. It is used for
network troubleshooting, analysis, software and communications protocol
development, and education.
To use:
1. Install Wireshark.
2. Open your Internet browser.
3. Clear your browser cache.
4. Open Wireshark
5. Click on "Capture > Interfaces,
6. You probably want to capture traffic that goes through your
ethernet driver. Click on the Start button to start capturing traffic via this
interface.
7. Visit the URL that you wanted to capture the traffic from.
8. Go back to your Wireshark screen and press Ctrl + E to stop
capturing.
9. After the traffic capture is stopped, please save the captured traffic
into a *.pcap format file and attach it to your support ticket.
Practice Exercise:
References https://developer.mozilla.org/en-US/docs/Web
PART –A
Exercise 1
Objective:
To understand the basic structure of HTML and the basic tags
Explanation:
Recorded Demonstration 2: To understand the basic tags
Practice Exercises:
1) Write a HTML code using <table> tag to create a table structure as shown below. Use
spanning of columns and rows wherever necessary. [
2) Create a HTML page which embeds a youtube video in it. Place the video exactly in
the center of the web page. Add a Header and footer section to the web page with
appropriate information
3) Create a HTML form as shown below. Add input elements like color chooser, date
picker, meter, range etc., to make the form user friendly. Also group the iput types
into fieldset and label them using legend
4) Create an Online Resume webpage for yourself in the format given below. Start with
your name, address and phone number. Use an alternate typeface such as Arial.
Birla Institute of Technology and Science, Pilani
Work Integrated Learning Programme
LAB HANDOUT
PART –A
Objective:
To understand the use and need of CSS
Explanation:
Recorded Demo : Use of CSS to add effects to web pages
Select elements using CSS Selectors
Practice Exercises:
1) Below is the HTML code of a BITS Pilani course web page without CSS.
The webpage contains various sections header, menu, link, footer etc.,
Use css and add a external stylesheet reference to the web page.
Code for Web Page:
<!DOCTYPE html>
<html>
<head>
<title>BITS Pilani Course Directory</title>
</head>
<body>
<div id="container">
<header>
<h1><span class="blue-text"> BITS Pilani</span> Course
Directory</h1>
<h2>Find a course <span class="white-
text">NOW</span></h2>
</header>
<nav id="menu">
<ul>
<li class="menu"><a href="index.html">Home</a></li>
<li class="menu"><a href="about.html">About
Us</a></li>
<li class="menu"><a
href="browse.html">Courses</a></li>
<li class="menu"><a href="contact.html">Contact
Us</a></li>
</ul>
</nav>
<aside>
<nav id="leftmenu">
<h3>Links</h3>
<ul>
<li><a href="browse.html">DBMS</a></li>
<li><a href="browse.html">PHP</a></li>
<li><a href="browse.html">DevOps</a></li>
<li><a href="browse.html">jQuery</a></li>
<li><a href="browse.html">Web design</a></li>
<li><a href="browse.html">Web
Programming</a></li>
<li><a
href="browse.html">Microservices</a></li>
<li><a href="browse.html">Internet
Marketing</a></li>
<li><a href="browse.html">XHTML
Templates</a></li>
</ul>
</nav>
</aside>
<section>
<h2>BITS Pilani Course Directory </h2>
<h3>Who Are We?</h3>
<p> Search and browse courses </p>
<h3>What are the courses we have?</h3>
<p>Our course languages like HTML5, XHTML and XML to programming languages
such as Javascript, PHP, Python and ASP</p>
</section>
</div><!--container end-->
<div style="clear;both"></div>
<footer>
Copyright © 2018, BITS-Pilani
</footer>
</body>
</html>
2) Write an HTML document that shows the results of a color survey. The document
should contain a form with radio buttons that allows users to votefor their favorite
color. One of the colors should be selected as a default. The document should also
contain a table showing various colors and the corresponding percentage of votes for
each color. (Each row should be displayed in the color to which it is referring.) Use
attributes to format width, border and cell spacing for the table
3) Box Model Exercise
Copy this webpage code.
Add appropriate margin, border, and padding to the text div.
Add appropriate border to the image.
Create a div for all of the page content and center that in the middle of the
page. Add appropriate border and padding to that div.
Experiment with different values for box model properties and
understand the positioning of element
CODE:
<!DOCTYPE html>
<html>
<head>
<style>
div.ex1 {
width: 300px;
background-color: yellow;
}
div.ex2 {
width: 300px;
padding: 5px;
box-sizing: border-box;
background-color: lightblue;
}
</style>
</head>
<body>
<h2>Padding and element width</h2>
<img src="Logo.png" width="100" height="100">BITS-Logo</img>
<div class="ex1">This div is 300px wide.</div>
<br>
<div class="ex2">The width of this div remains at 300px, in spite of
the 50px of total left and right padding, because of the box -sizing:
border-box property.
</body>
</html>
https://developer.mozilla.org/en-
US/docs/Learn/CSS/CSS_layout/Practical_positioning_examples
5) For each of the following CSS rule(s), write the words (e.g. “Div2”) that will appear
red or green in the browser and specify the color. Rules from one part do not apply to
the next part. Briefly justify your answers for each part by stating what the CSS rules
are doing.
Code:
<html>
<body>
<div id="div1">Div1</div>
<div id="div2" class="class1">Div2</div>
<div>Div3
<span id="span1" class="class1">span1</span>
<span id="span2" class="class2">span2</span>
</div>
<div>Div4</div>
<span>span3</span>
</body>
</html>
CSS RULES:
PART –A
Exercise 1:
<html>
<body>
<input type="button" value="Click to set paragraph background color"
onclick="set_background()">
<p>This is a paragraph element </p>
</body>
</html>
5) Write a function normalize, that replaces "-" with "/" in a date string.normalize("20-
05-2017") should return "20/05/2017".
HINT:
The replace method replaces a substring with another:
var str = "JavaScript";
var newstr = str.replace("Java", "ECMA");
"Java" is replaced with "ECMA". Thus newstr has the value "ECMAScript". The
original string remains unchanged. Only the first occurrence is replaced:
var newstr = "Dada".replace("a", "i");
newstr has the value "Dida" and not "Didi".
Code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
function switchTest(SetOption) {
OptionsSelect = document.frmOne.SetOption.value
alert(OptionsSelect);
switch (OptionsSelect) {
case "1":
alert("Arizona")
break
case "2":
alert("New Mexico")
break
case "3":
alert("California")
break
default:
alert("Cannot be determined")
}
}
</script>
<body>
<h3>JavaScript</h3>
<form name = "frmOne">
<select name= "SetOption" onchange="switchTest(this)">
<option value = "0">Select a City - See the State!</option>
<option value = "1">Phoenix</option>
<option value = "2">Roswell</option>
<option value = "3">Sacramento</option>
<option value = "4">My city</option>
<option value = "5">Your city</option>
</select>
</form>
</body>
</html>