Performing Basic Window function in JavaScript

by | Dec 25, 2020 | JavaScript

Home » Website Development » JavaScript » Performing Basic Window function in JavaScript

Performing Basic Window function in JavaScript

The Window object is supported by all the browsers and is used to represent a browser’s window. We can perform various functions using the Window Objects. Following are the widely used Window functions with their description:

Window FunctionDescriptionExample
window.alert( )This method displays an alert box with your message and OK button.window.alert(“Hello World”);
window.confirm( )This method displays a dialog box with an optional message and two buttons i.e. OK and Cancel.if (window.confirm(“Do you want to exit?”)) {window.alert(“Thanks for Visiting!”); }
window.prompt( )This method opens a dialog box that prompts a user for input.prompt(“What’s your name?”);
window.print( )This method prints the current screen.window.print( ); )This method is used to open a new browser window or a new tab. This is mainly used to open a link in a new“”);
window.close( )This method closes the current window. This only works if the window was opened using =“”, “newWindow”, “width=200, height=100”);


window.history.back( )This method loads the previous URL from the history list.window.history.back();
window.history.forward( )This method loads the next URL from the history list.window.history.forward();
window.localStorage( )This method is used to store & retrieve data (key/ value pair) from the browser’s local storage.window.localStorage.setItem(‘myName’, ‘Rudra’);


window.sessionStorage( )This is same as the above function, the difference is that the data gets deleted once the session is closed (i.e. browser’s tab is closed)window.sessionStorage.setItem(‘myName’, ‘Rudra’);


*Note: Please try the above examples in your browser’s console.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.