DOM
DOM
The Browser Object Model (BOM) allows JavaScript to "talk to" the browser.
"BOM" stands for Browser Object Model. It represents the objects that a browser
provides to JavaScript to interact with the browser itself.
The BOM includes objects like:
BOM
Window: The global object in a browser's environment. It represents the browser window or
tab and contains properties like window. location (which gives information about the
current URL), window. document (which refers to the DOM document in the current
window), and many others.
1. Document: Represents the DOM (Document Object Model) of a web page. It provides
methods and properties to interact with the contents of the page.
2. Location: Represents the current URL of the browser and allows you to interact with it.
3. Navigator: Provides information about the browser itself, such as its name, version, and
capabilities.
4. Screen: Represents the user's screen. It provides information about the dimensions and
pixel depth of the screen.
5. History: Allows manipulation of the browser's history (back, forward, etc.).
Window. Screen
The window.screen object contains information about the user's
screen.
The window.screen object can be written without the window
prefix
Properties:
•screen.width
•screen.height
•screen.availWidth
•screen.availHeight
•screen.colorDepth
•screen.pixelDepth
Window.location
The window.location object can be used to get the current page address (URL)
and to redirect the browser to a new page.
Some examples:
•window.location.href returns the href (URL) of the current page
•window.location.hostname returns the domain name of the web host
•window.location.pathname returns the path and filename of the current page
•window.location.protocol returns the web protocol used (http: or https:)
•window.location.assign() loads a new document
Window.history and window.navigator
Window.history object contains the browser history.
Some methods:
•history.back() - same as clicking back in the browser
•history.forward() - same as clicking forward in the browser
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
Alert Box
An alert box is often used if you want to make sure information comes through to
the user.
When an alert box pops up, the user will have to click "OK" to proceed.
JavaScript Popup Boxes
Confirm Box
A confirm box is often used if you want the user to verify or accept
something.
When a confirm box pops up, the user will have to click either "OK" or
"Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the
box returns false.
JavaScript Popup Boxes
Prompt Box :
A prompt box is often used if you want the user to input a value
before entering a page.
When a prompt box pops up, the user will have to click either "OK"
or "Cancel" to proceed after entering an input value.
If the user clicks "OK" the box returns the input value. If the user
clicks "Cancel" the box returns null.
DOM(Document Object Model)
In JavaScript, the DOM (Document Object Model) is a programming
interface for web documents. It represents the structure of a document as a
tree-like model where each node is an object representing a part of the
document, such as elements, attributes, and text.
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:
DOM Manipulation
Async : The async keyword is used to define a function that returns a promise. It
allows you to write
Await : The await keyword is used inside an async function to wait for a Promise
to settle (either resolve or reject). It can only be used inside an async function