Browser Object Model | Javascript Hindi Course For Beginners ( 2023 ) #10

 

What is Window Object

 
window object represents the current browser window or tab. It is a global object that provides access to many properties and methods that can be used to interact with the browser environment.
Note that the window object is a global object, which means that you don't need to explicitly reference it in most cases. For example, you could simply write alert("Hello, world!") instead of window.alert("Hello, world!") .
 

Timing methods

setTimeout(): Executes a function after a specified number of milliseconds.
clearTimeout()is a JavaScript function that cancels a timeout previously set with the setTimeout()function. It takes one parameter, which is the ID of the timeout to be canceled.
We can cancel the timeout using clearTimeout()and passing in the timeoutIdvariable as the parameter. This will prevent the sayHello()function from being called after the 5-second delay.
Note that if the timeout has already been executed before clearTimeout() is called, then clearTimeout() has no effect.
It's good practice to always cancel a timeout when it is no longer needed to prevent any unintended consequences or performance issues.
 
setInterval()is a built-in JavaScript function that repeatedly executes a function at a specified interval (in milliseconds) until it is stopped.
 
 
Dialog Methods
  • alert(): Displays an alert box with a message and an OK button.
  • prompt(): Displays a dialog box with a message, an input field, and OK and Cancel buttons. Returns the value entered by the user.
  • confirm(): Displays a dialog box with a message and OK and Cancel buttons. Returns a Boolean value indicating whether the user clicked OK or Cancel.
 
 
Location Methods
  • location.href returns the href (URL) of the current page
  • location.hostname returns the domain name of the web host
  • location.pathname returns the path and filename of the current page
  • location.protocol returns the web protocol used (http: or https:)
  • location.assign() loads a new document