Windows Objects in Javascript: Explained

What is the window property in javascript?

Windows Objects in Javascript represents the current browser window or tab and provides access to many properties and methods related to it. Some of the most commonly used properties and methods of the window object are:

An example of using Windows Objects in Javascript (Properties)

There are so many Windows properties in Javascript

  • window.innerWidth and window.innerHeight – returns the width and height of the window’s viewport (the visible area of the window)
  • window.location – returns information about the current URL of the window
  • window.document – returns the current HTML document loaded in the window
  • window.screen – returns information about the user’s screen

An example of using Windows Objects in Javascript (Methods)

The Windows methods in Javascript has many methods which include

  • window.alert() – displays a pop-up message box
  • – opens a new window or tab
  • window.close() – closes the current window or tab
  • window.scrollTo() – scrolls the window to a specified position
  • window.setTimeout() – sets a delay before executing a function. Read More
  • window.print() – This is a method in JavaScript that opens the print dialog of the browser, allowing the user to print the current page or a selected part of it. This method is often used in web applications to provide a convenient way for users to print the contents of a page. When window.print() is called, the browser displays the standard print dialog, which allows the user to select the printer, set print options, and start the print process. Read more

Here’s an example of how you can use window.print() in your JavaScript code:

function printPage() { window.print(); }

In this example, the printPage function calls window.print() to open the print dialog when it is executed. This function can be triggered by a button click or other user interaction, or it can be automatically called when the page loads.

See also  Startup Acquisition Marketplaces: 5 Top Things To Know

These are just a few of the many Windows objects in Javascript (properties and methods) available on the window object. For a complete reference, you can refer to the JavaScript documentation. is a method in JavaScript that opens a new window or tab in the browser. It can be used to load a new web page, display an HTML document, or display content from another source, such as an image or a PDF file.

Here’s the basic syntax for, name, specs);

• URL (required) – The URL of the page to be opened. It can be a full URL, a relative URL, or a data URL.
• name (optional) – A name for the new window. This name can be used to target the window with JavaScript.
• specs (optional) – A string that specifies the features of the new window. It can include features such as the window’s size, position, and whether it has a toolbar, scrollbars, etc.
Here’s an example of how you can use in your JavaScript code:

function openWindow() {
'width=800, height=600'

In this example, the openWindow function calls to open a new window when it is executed. The new window will have the specified URL, name, and size. The function can be triggered by a button click or other user interaction.

Read Also: Javascript Animations: How to make an Element move With JavaScript

Like and Follow Us on Facebook: Flourish Tech-House

Originally posted 2023-02-14 09:26:17.



Leave a Reply

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