Unit 3
Unit 3
Introduction: HTML stands for Hyper Text Markup Language. It is used to design
web pages using a markup language. HTML is an abbreviation of Hypertext and
Markup language. Hypertext defines the link between the web pages. The
markup language is used to define the text document within the tag which
defines the structure of web pages. HTML 5 is the fifth and current version of
HTML. It has improved the markup available for documents and has introduced
application programming interfaces (API) and Document Object Model (DOM).
Features:
It has introduced new multimedia features which supports both audio and
video controls by using <audio> and <video> tags.
There are new graphics elements including vector graphics and tags.
Enrich semantic content by including <header> <footer>, <article>,
<section> and <figure> are added.
Drag and Drop- The user can grab an object and drag it further dropping it
to a new location.
Geo-location services- It helps to locate the geographical location of a
client.
Web storage facility which provides web application methods to store data
on the web browser.
Uses SQL database to store data offline.
Allows drawing various shapes like triangle, rectangle, circle, etc.
Capable of handling incorrect syntax.
Easy DOCTYPE declaration i.e., <!doctype html>
Easy character encoding i.e., <meta charset=”UTF-8″>
Removed elements from HTML 5: There are many elements which are
depreciated from HTML 5 are listed below:
<acronym> <abbr>
<applet> <object>
<basefont> CSS
<big> CSS
Removed Use Instead
Elements Elements
<center> CSS
<dir> <ul>
<font> CSS
<frame>
<frameset>
<noframes>
<isindex>
<tt> CSS
CSS3:
CSS3 stands for Cascading Style Sheets Level 3. It is an advanced version of CSS,
used for structuring, styling, and formatting web pages. CSS3 introduces several
new features and is supported by all modern web browsers. One of the most
significant advancements in CSS3 is the splitting of CSS standards into separate
modules, making it simpler to learn and use.
New Features of CSS3
1. Combinator: CSS3 introduces a new general sibling combinator, which
matches sibling elements using the tilde (~) combinator.
2. CSS Selectors: CSS3 selectors are more advanced than the simple
selectors offered by CSS, providing a sequence of easy-to-use and simple
selectors.
3. Pseudo-elements: CSS3 adds many new pseudo-elements for easier and
more detailed styling. The new convention of double colons (::) is also
introduced.
4. Border Style: CSS3 includes new border styling features like border-
radius, border-image-slice, border-image-source, and values for “width
stretch”.
5. Background Style Properties: CSS3 introduces new background style
properties such as background-clip, background-size, background-style,
and background-origin.
WebSocket
WebSocket is bidirectional, a full-duplex protocol that is used in the same
scenario of client-server communication, unlike HTTP which starts
from ws:// or wss://. It is a stateful protocol, which means the connection
between client and server will stay alive until it gets terminated by either party
(client or server). After closing the connection by either of the client or server,
the connection is terminated from both ends.
Let’s take an example of client-server communication, there is the client which is
a web browser, and a server, whenever we initiate the connection between client
and server, the client-server makes the handshaking and decides to create a new
connection and this connection will keep alive until terminated by any of them.
When the connection is established and alive the communication takes place
using the same connection channel until it is terminated.
This is how after client-server handshaking, the client-server decides to keep a
new connection alive, this new connection will be known as WebSocket. Once the
communication link is established and the connections are opened, message
exchange will take place in bidirectional mode until the connection persists
between client-server. If anyone of them (client-server) dies or decide to close
the connection then it is closed by both the party. The way in which the socket
works is slightly different from how HTTP works, the status code 101 denotes the
switching protocol in WebSocket.
Output:
HTML Canvas Tag with JavaScript
A canvas is a two dimensional grid.
Coordinates (0,0) defines the upper left corner of the canvas. The parameters
(0,0,200,100) is used for fillRect() method. This parameter will fill the rectangle
start with the upper-left corner (0,0) and draw a 200 * 100 rectangle.
1. <canvas id="myCanvas" width="250" height="150" style="border:1px s
olid #c3c3c3;">
2. Your browser does not support the HTML5 canvas tag.
3. </canvas>
4. <script>
5. var c = document.getElementById("myCanvas");
6. var cctx = c.getContext("2d");
7. ctx.fillStyle = "#FF0000";
8. ctx.fillRect(0,0,200,100);
9. </script>
Output:
1. ctx.strokeText("Hello JavaTpoint",10,50);
Attributes
Attribute Value Description
autoplay autoplay Specifies that the audio will start playing as soon as it is
ready
loop loop Specifies that the audio will start over again, every time
it is finished
preload auto Specifies if and how the author thinks the audio should
metadata be loaded when the page loads
none
Example
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
autoplay autoplay Specifies that the video will start playing as soon as it is
ready
loop loop Specifies that the video will start over again, every time
it is finished
muted muted Specifies that the audio output of the video should be
muted
preload auto Specifies if and how the author thinks the video should
metadata be loaded when the page loads
none
Example
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
Event Description
Drag It fires every time when the mouse is moved while the object is being dragged
Dragstart It is a very initial stage. It fires when the user starts dragging object.
Dragenter It fires when the user moves his/her mouse cursur over the target element.
Dragover This event is fired when the mouse moves over an element.
Dragend It fires when user releases the mouse button to complete the drag operation.
HTML5 Geolocation
The Geolocation is one of the best HTML5 API which is used to identify the user's
geographic location for the web application.
This new feature of HTML5 allows you to navigate the latitude and longitude
coordinates of the current website's visitor. These coordinates can be captured
by JavaScript and send to the server which can show your current location on the
website
Most of the geolocation services use Network routing addresses such as IP
addresses, RFID, WIFI
User privacy:
The user's location is the privacy concern, so geolocation API protects the user's
privacy by taking the user's permission before getting the location. Geolocation
API sends a notification prompt box which user can allow or deny, and if the user
allows then only his location will be identified.
Geolocation object
The Geolocation API is work with the navigation.geolocation object. Its read-only
property returns a Geolocation object which identifies the location of the user
and can generate a customized result based on user location.
Syntax:
1. geo=navigator. geolocation;
If this object is present, then you can get the geolocation services.
Geolocation Methods
The Geolocation API uses three methods of Geolocation interface which are given
following:
Methods Description
The below example will return the longitude and latitude of the visitor's current
location.
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Geolocation API</title>
5. </head>
6. <body>
7. <h1>Find your Current location</h1>
8. <button onclick="getlocation()">Click me</button>
9. <div id="location"></div>
10.<script>
11. var x= document.getElementById("location");
12. function getlocation() {
13. if(navigator.geolocation){
14. navigator.geolocation.getCurrentPosition(showPosition)
15. }
16. else
17. {
18. alert("Sorry! your browser is not supporting")
19. }}
20.
21. function showPosition(position){
22. var x = "Your current location is (" + "Latitude: " + position.coords.lati
tude + ", " + "Longitude: " + position.coords.longitude + ")";
23. document.getElementById("location").innerHTML = x;
24. }
25.</script>
26.</body>
27.</html>
Explanation:
o First checking the browser support
Example
1. function showError(error) {
2. switch(error.code){
3. case error.PERMISSION_DENIED:
4. alert("User denied the request for Geolocation API.");
5. break;
6. case error.POSITION_UNAVAILABLE:
7. alert("USer location information is unavailable.");
8. break;
9. case error.TIMEOUT:
10. alert("The request to get user location timed out.");
11. break;
12. case error.UNKNOWN_ERROR:
13. alert("An unknown error occurred.");
14. break;
15. }
16. }
Displaying location on Google Map
Till now, we have seen how to show your location using latitude and longitude
values, but it is not sufficient. Hence we can also show the exact location on
Google map with this API.
Following example showing the location using Google Map.
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Geolocation API</title>
5. </head>
6. <body>
7. <h2>Find Your Location in below Map</h2>
8. <button onclick="getlocation();"> Show Position</button>
9. <div id="demo" style="width: 600px; height: 400px; margin-left: 200
px;"></div>
10.
11. <script src="https://maps.google.com/maps/api/js?sensor=false"> <
/script>
12.
13. <script type="text/javascript">
14. function getlocation(){
15. if(navigator.geolocation){
16. navigator.geolocation.getCurrentPosition(showPos, showErr);
17. }
18. else{
19. alert("Sorry! your Browser does not support Geolocation API")
20. }
21. }
22. //Showing Current Poistion on Google Map
23. function showPos(position){
24. latt = position.coords.latitude;
25. long = position.coords.longitude;
26. var lattlong = new google.maps.LatLng(latt, long);
27. var myOptions = {
28. center: lattlong,
29. zoom: 15,
30. mapTypeControl: true,
31. navigationControlOptions: {style:google.maps.NavigationControl
Style.SMALL}
32. }
33. var maps = new google.maps.Map(document.getElementById("de
mo"), myOptions);
34. var markers =
35. new google.maps.Marker({position:lattlong, map:maps, title:"You a
re here!"});
36. }
37. //Handling Error and Rejection
38. function showErr(error) {
39. switch(error.code){
40. case error.PERMISSION_DENIED:
41. alert("User denied the request for Geolocation API.");
42. break;
43. case error.POSITION_UNAVAILABLE:
44. alert("USer location information is unavailable.");
45. break;
46. case error.TIMEOUT:
47. alert("The request to get user location timed out.");
48. break;
49. case error.UNKNOWN_ERROR:
50. alert("An unknown error occurred.");
51. break;
52. }
53. } </script>
54. </body>
55.</html>
Location properties
The getCurrentPosition() method of Geolocation API returns callback methods
which retrieve the user location information. This callback method returns a
Position Object which contains all location information and specifies different
properties. It always returns latitude and longitude properties, but the following
table describes some other properties of Position object.
Properties Description
Microdata
HTML Microdata is a form of semantic markup that provides additional
information about specific elements on a web page. This information is encoded
in the page's HTML code and can be used by search engines to better
understand the context and content of the page.
Microdata uses a set of standard properties and values, such
as itemprop and itemtype, to describe specific elements on a web page. Search
engines then use this information to provide more accurate search results,
improving the ranking of your website in search engines.
HTML Microdata works by adding additional information to the HTML code of a
web page. This information is encoded in the form of microdata properties and
values, which describe specific elements on the page.
For example, a web developer could use Microdata to provide information about
a product on an e-commerce website. This information could include the
product's name, price, and availability and be encoded as microdata properties
and values in the HTML code.
Once this information is added to the HTML code, search engines can use it to
provide more accurate and relevant information in search results, improving the
visibility and ranking of the website in search engines.
<div itemscope itemtype="http://schema.org/Product">
<h1 itemprop="name">Product Name</h1>
<span itemprop="price">$10.99</span>
<meta itemprop="availability" content="in_stock" />
</div>
Attribute Description
itemsco This attribute specifies that the HTML5 element is a microdata item. By
pe using this attribute, you are indicating to search engines that the element
contains structured data that should be considered as a single unit.
itemtyp This attribute specifies the type of the microdata item, using a URL or a
e vocabulary-specific string. This information helps search engines
understand the context and content of the element and the type of
information it contains.
itemid This attribute specifies a unique microdata item identifier using a URL.
This identifier can reference the microdata item from other parts of the
web page or other web pages.
itempro This attribute specifies a property of the microdata item and associates it
p with the content of the HTML element. For example, you could use this
attribute to specify the author of a book or the date of an event.
itemref This attribute allows you to associate properties with a microdata item
that is located outside of the HTML5 element that has
the itemscope attribute
Browser
A web browser is an application used to access and interact with information on
the World Wide Web, such as web pages, videos, and images. The term
"browser" predates the web and referred to programs that allowed users to
navigate and read text files online.
Web browsers use HTTP to request information from web servers. While most
browsers support email and FTP, specialized programs are often used for these
tasks.
The first web browser, World Wide Web (later renamed Nexus), was created in
1990. Mosaic, the first browser with a graphical interface, launched in 1993,
influencing later browsers like Netscape Navigator and Internet Explorer.
Browser lifecycle
The browser lifecycle refers to the sequence of steps a web browser goes
through to load, render, and manage web content. Here's a simplified breakdown
of the browser lifecycle:
1. Navigation/Request
User Input: The user types a URL, clicks a link, or submits a form.
Request Sent: The browser sends an HTTP request to the server hosting
the website.
2. Server Response
Response Received: The server responds with the requested resources
(HTML, CSS, JavaScript, etc.).
Status Code: The browser checks the HTTP status code (e.g., 200 for
success, 404 for not found).
3. Page Loading
HTML Parsing: The browser starts parsing the HTML document.
Resource Fetching: Additional resources (CSS, images, JavaScript files)
are fetched from the server or cache.
4. Rendering
DOM Creation: The browser builds the Document Object Model (DOM)
from the HTML.
CSSOM Creation: The browser constructs the CSS Object Model (CSSOM)
from the CSS.
JavaScript Execution: JavaScript code is executed, modifying the DOM or
CSSOM as needed.
Render Tree: The DOM and CSSOM combine to form a render tree,
defining how elements should appear on the page.
5. Layout
Layout Calculation: The browser calculates the size, position, and
dimensions of each element based on the render tree.
6. Painting
Visual Rendering: The browser converts the layout and styles into pixels
and renders them on the screen.
7. Interactivity
User Interaction: The browser remains interactive, responding to user
actions like clicks, scrolls, and form inputs.
JavaScript Handling: JavaScript can continuously modify the DOM and
respond to events, such as mouse clicks or key presses.
8. Reflow and Repaint (Dynamic Changes)
Reflow: If the DOM or CSS is modified (e.g., by JavaScript), the browser
recalculates the layout of the affected elements (reflow).
Repaint: The browser repaints the screen to reflect visual changes after
reflow or style updates.
9. Session Termination/Closure
Page Unload: When the user navigates away or closes the browser tab,
the page unload event is triggered, and cleanup tasks like saving session
data or clearing resources occur.
This lifecycle repeats every time a user navigates to a new page or interacts with
the current one.