DEV Community

loading...
Cover image for Amazing Window Object With JS (Part 1)

Amazing Window Object With JS (Part 1)

nikhil27b profile image Nikhil Bobade ・2 min read

Window Object :

The window object represents an open window in a browser. The window object is very useful in javascript also you can do many things with the window object.
We have many properties in the window object. An object of the window is created automatically by the browser.

1.Window Confirm :

Window confirm is used for displays a dialog box with a specified message, along with an OK and a Cancel button.
A confirm box is often used if you want the user to verify or accept something.

Example :

confirm("Press the button");
Enter fullscreen mode Exit fullscreen mode

Output :
Alt Text

2.Window focus :

The window focus method is also used to focus the thing in the browsers or website.
Means for example you want to focus on a specific thing or tracking purpose so you can be use window focus.

Example
var myWindow = window.open("", "", "width=200, height=100");   
myWindow.document.write("<p>A new window!</p>");         
myWindow.focus();  
Enter fullscreen mode Exit fullscreen mode
Output

Alt Text

3.Window Local Storage:

The localStorage is also a window property this is very useful to store data in the browser and sessionStorage properties allow saving key/value pairs in a web browser.

The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed and will be available the next day, week, or year.

4.Window getComputedStyle:

The getComputedStyle() is a very useful property i also use this propety a lot getComputedStyle() is gets all the actual (computed) CSS property and values of the specified element.

Example

Alt Text

5.Window Print:

The window print is a very important and useful dom element in the javascript. The print() method prints the contents of the current window.

Example

Alt Text

I hope you like this also comments about your thoughts.

For more content follow me on Instagram @developer_nikhil27.

Thank you.

Discussion (0)

Forem Open with the Forem app