</> Code Corner

JavaScript · JS Browser BOM · Lesson 55

JS Window & Location

The window, screen, location and history objects.

The Browser Object Model (BOM) allows JavaScript to "talk to" the browser. The window object represents the browser window; all global variables and functions are its members.

Example

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
  "Inner size: " + window.innerWidth + " x " + window.innerHeight + "<br>" +
  "Screen: " + screen.width + " x " + screen.height + "<br>" +
  "Location: " + window.location.href + "<br>" +
  "History length: " + history.length + "<br>" +
  "Language: " + navigator.language;
</script>
Object Use
window.innerWidth / innerHeight Viewport size
window.location Current URL; location.href = "..." navigates
window.history back() and forward()
window.navigator Information about the browser
window.screen The user's screen

Keep reading “JS Window & Location”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋