DEV Community

loading...
Cover image for Window Object in JavaScript

Window Object in JavaScript

rahxuls profile image Rahul ・2 min read

The most important object in the Browser Object Model is the window object.

It helps in accessing information about the browser and its components. To access these features, it has various methods and properties.




(Please scroll a bit below I don't know why this is happening. Use the scroll bar plz.)







































































































































































































































































































































Property Description
window.closed Whether the window has been closed
window.length Number of <iframe> elements in the window
window.name Gets or sets the window name
window.innerHeight height of the window
window.innerWidth width of the window
window.screenX X-cordinate of the pointer, relative to the top left corner of screen
window.screenY Y-cordinate of the pointer, relative to the top left corner of screen
window.location current URL of window object
window.history Reference to history object for browser window or tab
window.screen Reference to object
window.pageXoffset Distance document has been scrolled horizantally
window.pageYoffset Distance document has been scrolled vertically
window.alert() creates dialog box with message OK button
window.blur() Remove focus from window
window.close() closes a browser window
window.confirm() Creates dialog box with message, and OK button and a **cancel **button
window.getComputedStyle() Get CSS styles applied to an element
window.moveTo(x,y) Move a window's left and top edge to supplied coordinates
window.open() Opens new browser window with URL specified as parameter
window.print() Tells browser that user wants to print contents of current page
window.prompt() Creates dialog box for retrieving user input
windows.scrollBy() Scroll the document by the specified number of pixels
windows.scrollTo() Scolls the document to the specified coordinates
window.setInterval() Do something repeatedly at specified intervals
windows.setTimeOut() Do something after a specified amount of time
window.stop() Stop window from loading



Short and Informative Post for you all. 😀

⚡Happy Coding

Discussion (7)

pic
Editor guide
Collapse
willemodendaal profile image
Willem Odendaal

The scrolling had me in suspense 😄

It's worth noting that Javascript can run on the "server" as well with Node, in which case the "window" object does not exist. That can get confusing when you're using something like NextJS to use the same code to render HTML dynamically in the browser, and on the server for SEO purposes.

Collapse
aminnairi profile image
Amin

Hi Willem!

Believe it or not, but the Window object is well defined in Deno, which is awesome and can make isomorphic code that can work both on the client as well as the server.

doc.deno.land/builtin/stable#Window

Collapse
rahxuls profile image
Rahul Author

Uh🤪 I'm sorry.

Collapse
janpauldahlke profile image
jan paul

Awesome scroll experience man ;-)

Collapse
rahxuls profile image
Rahul Author

Sorry tho.

Collapse
marceliwac profile image
Marceli-Wac

What's with the scrolling haha Great post, I'd love to see example use cases and code with those too!

Collapse
rahxuls profile image
Rahul Author

I don't why it happened.