JavaScript Window Methods

Beginner
6 min read
Updated: Nov 2026
23 method guides
Method index

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().

Beginner path.

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:

JavaScript
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 methods

Message, confirm, and text boxes the browser draws for you.

MethodDescriptionTutorial
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 methods

Turn a string into Base64, or turn Base64 back into a string.

MethodDescriptionTutorial
btoa()Encodes a binary string as Base64. btoa("Hi") is "SGk=".Open
atob()Decodes a Base64 string into a binary string.Open

Focus, open, and print

6 methods

Focus this window, open another one, print the page, or stop loading.

MethodDescriptionTutorial
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 methods

Run a function later, repeat it, or cancel the id the timer returned.

MethodDescriptionTutorial
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 methods

Move the document by a relative offset or to an absolute position.

MethodDescriptionTutorial
scrollBy()Scrolls the document by a relative number of pixels.Open
scrollTo()Scrolls the document to an absolute position.Open

Move and resize

4 methods

Move or resize the browser window. Browsers often ignore these without a user gesture.

MethodDescriptionTutorial
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 methods

Read the styles the browser computed, or test a media query.

MethodDescriptionTutorial
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

Window methods are functions on the window object. alert(), confirm(), and prompt() show browser dialogs. setTimeout() and setInterval() schedule functions. open(), scrollTo(), and matchMedia() work with the tab, the document, and CSS media queries.
The Window page teaches what the browser tab object is—self, properties versus methods, and a timer id. This Methods index lists every method tutorial so you can open alert(), setTimeout(), and the rest.
Use the window object, or rely on it being global: window.alert("Saved") and alert("Saved") are the same call in a browser. setTimeout(fn, 1000) returns an id. clearTimeout(id) cancels it.
undefined. The dialog is a side effect. confirm() returns true or false. prompt() returns the string the reader typed, or null if they cancel.
If you are new, read JavaScript Window first. Then open alert(), setTimeout(), and open() from the tables below.

Start with alert()

Open the dialog guide—syntax, examples, and FAQs.

alert() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful