Web Technologies: Introduction To WWW, Web Protocols and Urls
Web Technologies: Introduction To WWW, Web Protocols and Urls
Introduction to WWW,
Web Protocols and URLs
Dr.Sarasvathi V
Department of
Computer Science and Engineering
Credit : Prof. Vinay Joshi
Introduction to WWW, Web Protocols and URLs
Common Terms
3
Introduction to WWW, Web Protocols and URLs
How does WWW work?
4
Introduction to WWW, Web Protocols and URLs
History of Web Browsers
2020
Microsoft
Edge Based
on chromium
Steps:
1. Choose a domain name
2. Register a domain and sign up with web hosting
3. Set up a website using WordPress/Name cheap/Go
Daddy (through web host)
4. Customize your website design and structure
5. Add pages and content to your website
Introduction to Web Protocols and HTTP
What is a Protocol?
server
HTTP: HyperText Transfer Protocol running
• Application Protocol used by the Apache
Web Web
server
• Client/Server model PC running
• Client: browser that requests, Firefox
receives, and “displays” Web browser
Objects
• Server: Web server sends Web
Objects (using HTTP protocol) in
response to requests
iphone
running
Safari
browser
Introduction to Web Protocols and HTTP
HTTP Overview…(cntd.)
• HTTP methods:
• GET: Retrieve static or dynamic content
• POST: Send content to server through request body
• OPTIONS: Get server or file attributes
• HEAD: Fetches only header field without any response body
• PUT: Write a file to the server
• DELETE: Delete a file on the server
Introduction to Web Protocols and HTTP
HTTP Response
Vinay Joshi
Department of
Computer Science and Engineering
HTML – Basic Markups
Introduction
• An HTML comment begins with <! – – and the comment closes with – –>.
• HTML comments are visible to anyone that views the page source code, but are not rendered when
the HTML document is rendered by a browser.
HTML – Basic Markups
Document Structure
<html>
<head>
<title>… </title>
</head>
<body>
…
</body>
</html>
HTML – Basic Markups
Document Structure Elements
title
body
HTML – Basic Markups
Common Tags / Elements
Images
Paragraph
Headings
Links
HTML – Basic Markups
Common Tags / Elements
• Text Content
• Paragraphs
• Headings
• Lists
• Tables
• Images
• Links
WEB TECHNOLOGIES
HTML 5
Vinay Joshi
Department of
Computer Science and Engineering
HTML5
Introduction
HTML – Forms
Vinay Joshi
Department of
Computer Science and Engineering
HTML – Forms
Introduction
HTML – Forms
Introduction
Syntax:
<form list_of_attributes_and_values>
<input element>
…
</form>
Important attributes of the <form> tag
• Method
• Action
• Target
Example:
<form method=“post” action=“survey.php” target=“_blank”>
<input type=“text”>
…
</form>
HTML – Forms
Methods
GET:
•Appends the form data to the URL, in name/value pairs
•NEVER use GET to send sensitive data! (the submitted form data is visible in the
URL!)
•The length of a URL is limited (2048 characters)
•Useful for form submissions where a user wants to bookmark the result
•GET is good for non-secure data, like query strings in Google
POST:
•Appends the form data inside the body of the HTTP request (the submitted form
data is not shown in the URL)
•POST has no size limitations, and can be used to send large amounts of data.
•Form submissions with POST cannot be bookmarked
HTML – Forms
Input widgets
• The email type is used for input fields that should contain an e-mail address.
• The value of the email field is automatically validated when the form is
submitted.
• The url type is used for input fields that should contain a URL address.
• The value of the url field is automatically validated when the form is
submitted.
• The number type is used for input fields that should contain a numeric value.
• The range type is used for input fields that should contain a value from a
range of numbers.
• The color type is used for input fields that should contain a color.
• This input type will allow you to select a color from a color picker:
The real power of using an external style sheet is that multiple web pages on
our site can link to the same style sheet:
style.css :
h2 {color:red;}
Styles declared in an external style sheet will affect all matching elements on all web
pages that link to the style sheet. By editing the external style sheet, we can make
site-wide changes (even to hundreds of pages) instantly.
CSS – Cascading Style Sheets and Selectors
Internal vs. External Style Sheets
For each XHTML element, the browser will combine all the styles
defined at different levels. For all conflicts, it will use the above priority
system to determine which format to display on the page.
In the prior example, the paragraph would display as red, because the
inline style "outranks" all the others.
CSS Selectors
Select the Elements to Apply CSS Rules
CSS – Cascading Style Sheets and Selectors
Selectors
• Primary Selectors
• Element selector
• Class Selectors
• ID selectors
• Nested Selector
• Multiple Selector
• Pseudo-selector
• Attribute selector
Primary Selectors: Select by Tag – ELEMENT SELECTORS
Select all
<span> elements
span {
background: DodgerBlue;
color: #ffffff;
}
Primary Selectors: Select by ID
Select <span>
with id="top"
span#top {
background: DodgerBlue;
}
34
Primary Selectors: Select by Class
<h1>Welcome…</h1>
<h2>My name is…</h2> h1, h2, p {
<p>I live in Duckburg.</p> background: yellow;
<p>My best friend is…</p> }
44
Pseudo Selector (:first-line)
• It allows us to add a border around elements and define space between elements.
CSS – Box Model and Position Property
Element support for styling
• There are two elements used commonly to style specific parts of a webpage
• <span>
• In-line element
• <div>
• Block element
CSS – Box Model and Position Property
Element support for styling
Block-level elements
• A block-level element always starts on a new line, and the browsers automatically add some
space (a margin) before and after the element.
• A block-level element always takes up the full width available (stretches out to the left and right
as far as it can).
Some example block-level elements are:
•<div>, <h1>-<h6>, <p>, <ul>,<nav>
In-Line elements
• An inline element does not start on a new line.
• An inline element only takes up as much width as necessary.
• Some example inline-level elements are:
•<span>, <a>, <input>,<button>,<img>
div {
Calculation:
320px (width)
width: 320px;
+ 20px (left + right padding)
padding: 10px;
+ 10px (left + right border)
border: 5px solid gray; + 0px (left + right margin)
margin: 0; = 350px
}
CSS – Box Model and Position Property
Background
JavaScript - Basics
- JavaScript programs are run by an interpreter built into the user's web browser
- Now the language has evolved with additional Server Side Scripting capabilities
(like in Node.JS)
JavaScript - Basics
Introduction to JavaScript…(cntd.)
<html>
<head>
<title>Hello World in JavaScript</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
JavaScript - Basics
JavaScript Code
<script src="myscript.js"></script>
Comments in JavaScript
- Single line comment : //
- Multiline comments : /* */
JavaScript - Basics
JavaScript Code – Using Semicolon
• var x = 5 + 5; // 10
var y = "5" + 5; //55
var z = "Hello" + 5; // Hello5
JavaScript - Basics
Loops
For/in loop:
The JavaScript for/in statement loops through the properties of
an object.
Vinay Joshi
Department of
Computer Science and Engineering
JavaScript – Arrays
Array
var num;
num = 6; num = 6;
console.log(num); console.log(num);
var num = 8; num = 8;
console.log(num); console.log(num);
WEB TECHNOLOGIES
JavaScript Objects
Vinay Joshi
Department of
Computer Science and Engineering
Javascript Objects
Basic Object Oriented Concepts
object1
Object
object2
Employee.prototype.showName = function(){…}
Javascript Objects
Creating an object using EcmaScript 6 Class Keyword
• Class is defined .
• Then the objects of the class are created.
• It internally uses the constructor/prototype
based approach of creating objects
WEB TECHNOLOGIES
- Math
- Number
- String
- Array
- Date
- window
- document
JavaScript – Built-in Objects
Array
for (i in arr)
console.log(typeof i + i));
// string 0
// string 1
JavaScript – Built-in Objects
Array
Or
Fruits[fruits.length] = “Lemon”
JavaScript Basics
JavaScript Arrays method
4) Shifting Elements
The shift() method removes the first array element and "shifts" all other elements to a
lower index.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();
The unshift() method adds a new element to an array (at the beginning
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon"); // Adds a new element "Lemon" to fruits
JavaScript Basics
JavaScript Arrays - Methods
5) Deleting Elements
var fruits = ["Banana", "Orange", "Apple", "Mango"];
delete fruits[0]; // Changes the first element in fruits to undefined
6) Splicing an Array
The splice() method changes the contents of an array by removing or replacing existing
elements and/or adding new elements in place
• The first parameter (2) defines the position where new elements should be added
(spliced in).
• The second parameter (0) defines how many elements should be removed.
• The rest of the parameters ("Lemon" , "Kiwi") define the new elements to be added.
• The splice() method returns an array with the deleted items:
Eg –
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 2, "Lemon", "Kiwi");
8) Sorting an Array
The sort() method sorts an array alphabetically.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); // Sorts the elements of fruits
- arr.sort([compareFunction])
- If compareFunction is not specified,array is sorted as strings in ascending order
- Arr = [1, 2, 11, 12, 22] var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) { return b
- Console.log(arr.sort())
- a; });
- // 1, 11, 12, 2, 22
console.log(numbers);
// [5,4,3,2,1]
- compareFunction takes two parameters say a and b and returns
- 1 if a > b
- 0 if a = b
- -1 if a < b
- To reverse the order modify the condition for returning 1, 0 and -1
Array.sort- Compare function
• compareFunction(Optional): A function that defines an alternative sort order.
The function should return a negative, zero, or positive value, depending on the
arguments, like:
function(a, b)
{return a-b}
• When the sort() method compares two values, it sends the values to the compare
function, and sorts the values according to the returned (negative, zero, positive)
value.
• Example:
• When comparing 40 and 100, the sort() method calls the compare
function(40,100).
• The function calculates 40-100, and returns -60 (a negative value).
• The sort function will sort 40 as a value lower than 100.
JavaScript – Built-in Objects
Number
Properties
• MIN_VALUE
• POSITIVE_INFINITY
• NEGATIVE_INFINITY
• When a web page is loaded, the browser creates a Document Object Model
of the page.
• The HTML DOM model is constructed as a tree of Objects.
• The HTML DOM is a standard object model and programming interface for
HTML. It defines:
<html>
<head>
<title>JavaScript DOM</title>
</head>
<body>
<p>Hello DOM!</p>
</body>
</html>
In this DOM tree, the document is the root node. The root node has one child
which is the <html> element. The <html> element is called the document element.
Document Object Model
Drawbacks of using document.write()
Method Description
document.createElement() Create a new element node using tag
document.createTextNode() Create a new text node
Property Description
node.textContent or Get or set the text content of an element
node.innerText node (without HTML tags)
node.innerHTML Get or set the HTML content enclosed in the
element tag
Document Object Model
Manipulating Nodes in the DOM
Method Description
node.appendChild() Add a node as the last child of the parent
element.
node.insertBefore() Insert a node into the parentbefore a
specific sibling node
node.replaceChild() Replace an existing node with a new node
node.removeChild() Removes child node
node.remove() Removes a node
Events
Vinay Joshi
Department of
Computer Science and Engineering
EVENT
What are Events?
EVENT
Events
element.on<event> = handler;
element.addEventListener(event, handler)
•Event listeners
Events
Event Sources and example events
Event Handling
Vinay Joshi
Department of
Computer Science and Engineering
Event Handling
Event Propagation
bubbling
• inner most element's event is handled first and then the outer: the
<p> element's click event is handled first, then the <div> element's
click event.
capturing
• outer most element's event is handled first and then the inner: the
<div> element's click event will be handled first, then the <p>
element's click event.
Event Handling
Event Propagation
Event Handling
Event Flow
Vinay Joshi
Department of Computer Science and Engineering
[email protected]
+91 80 2672 6622