JavaScript Window Methods

About This Index
This page is the JavaScript Window Methods index for the tutorial track. Each row links to a guide with syntax, examples, and FAQs.
Learn what the window is on /js/window. Use this page when you need a specific call such as alert(), setTimeout(), or open().
Start with alert(), setTimeout(), and open(). Then look up scrolling, Base64, and matchMedia().
How to Call a Window Method
In a browser these functions live on window:
window.alert("Saved");
const ok = window.confirm("Continue?");
const id = window.setTimeout(function () {
window.console.log("later");
}, 1000);
window.clearTimeout(id);
window.btoa("Hi"); // "SGk=" JavaScript Window Methods Table
All method guides in this JavaScript tutorial series (23 tutorials).
Dialogs
3 methodsMessage, confirm, and text boxes the browser draws for you.
| Method | Description | Tutorial |
|---|---|---|
alert() | Shows a message and an OK button. The call waits until the reader dismisses it, then returns undefined. | Open |
confirm() | Shows OK and Cancel. Returns true when the reader chooses OK, and false for Cancel. | Open |
prompt() | Asks for a line of text. Returns that string, or null if the reader cancels. | Open |
Base64
2 methodsTurn a string into Base64, or turn Base64 back into a string.
Focus, open, and print
6 methodsFocus this window, open another one, print the page, or stop loading.
| Method | Description | Tutorial |
|---|---|---|
blur() | Moves focus off this window. | Open |
focus() | Asks the browser to bring this window forward and focus it. | Open |
open() | Opens a new tab or window and returns that Window, or null if the browser blocks it. | Open |
close() | Closes a window this script opened with open(). Browsers keep the main tab open. | Open |
print() | Opens the browser print dialog for the current page. | Open |
stop() | Stops the window from loading more resources, like the Stop button. | Open |
Timers
4 methodsRun a function later, repeat it, or cancel the id the timer returned.
| Method | Description | Tutorial |
|---|---|---|
setTimeout() | Calls a function once after a delay in milliseconds, and returns an id you can cancel. | Open |
setInterval() | Calls a function again and again, waiting the given milliseconds between starts. | Open |
clearTimeout() | Cancels a one-shot timer started with setTimeout(). Pass the id setTimeout returned. | Open |
clearInterval() | Stops a repeating timer started with setInterval(). Pass the id setInterval returned. | Open |
Scrolling
2 methodsMove the document by a relative offset or to an absolute position.
| Method | Description | Tutorial |
|---|---|---|
scrollBy() | Scrolls the document by a relative number of pixels. | Open |
scrollTo() | Scrolls the document to an absolute position. | Open |
Move and resize
4 methodsMove or resize the browser window. Browsers often ignore these without a user gesture.
| Method | Description | Tutorial |
|---|---|---|
moveBy() | Moves the window by a pixel offset. Modern browsers limit this. | Open |
moveTo() | Moves the window to screen coordinates. Modern browsers limit this. | Open |
resizeBy() | Changes the window width and height by a pixel delta. | Open |
resizeTo() | Sets the window to an exact width and height in pixels. | Open |
CSS and media queries
2 methodsRead the styles the browser computed, or test a media query.
| Method | Description | Tutorial |
|---|---|---|
getComputedStyle() | Returns the CSS values the browser is using for an element. | Open |
matchMedia() | Tests a CSS media query and returns a MediaQueryList. matches is true or false. | Open |
Frequently Asked Questions
Start with alert()
Open the dialog guide—syntax, examples, and FAQs.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
12 people found this page helpful
