Global & Window Objects
window.document
→ Access the DOM.
window.location
→ Access and modify the URL.
window.history
→ Manage browsing history (back()
/ forward()
/ go(n)
).
window.navigator
→ Access browser information (navigator.userAgent
).
window.screen
→ Access screen details.
window.innerWidth / innerHeight
→ Get the current window size.
window.performance
→ Retrieve performance metrics.
Dialogs & User Interaction
window.alert(message)
→ Display an alert dialog.
window.confirm(message)
→ Display a confirmation dialog.
window.prompt(message, defaultValue?)
→ Display an input dialog.
alert("Hello, world!");
const isConfirmed = confirm("Are you sure?");
const userInput = prompt("Enter your name:");
Window Control & Utilities
window.open(url, target)
→ Open a new window/tab (may be blocked by pop-up blockers).
target
can be _self
, _blank
, _parent
, _top
.
window.scrollTo(x, y)
→ Scroll the page to a specific position.
window.scrollTo({ top: 500, behavior: "smooth" })
→ Smooth scroll.
setTimeout(callback, delay)
→ Execute code after a delay.
setInterval(callback, interval)
→ Execute code repeatedly at a given interval.
navigator.clipboard.writeText(text)
→ Copy text to clipboard.
navigator.clipboard.readText()
→ Read text from clipboard.