The Window Object

Window Methods, Objects, Properties

// Alert
alert('Hello World!');

// Prompt
const input = prompt();
console.log(input);

// Confirm
if (confirm('Are you sure?')){
    console.log('Yes');
}else{
    console.log('No');
}

Properties – height & width

Outer height and width

height = window.outerHeight;
width = window.outerWidth;

console.log('Window outer height: ' + height);
console.log('Window outer width: ' + width);

Inner height and width

height = window.innerHeight;
width = window.innerWidth;

console.log('Window inner height: ' + height);
console.log('Window inner width: ' + width);

Scroll points

val = window.scrollY;
val = window.scrollX;

console.log(val);

Location object

// Location Object
val = window.location;
val = window.location.hostname;
val = window.location.port;
val = window.location.href;

// Redirect
window.location.href = 'https://google.com';

// Reload
window.location.reload();

console.log(val);

Navigator Object

val = window.navigator;
val = window.navigator.appName;
val = window.navigator.appVersion;
val = window.navigator.userAgent;
val = window.navigator.platform;
val = window.navigator.language;

console.log(val); 
Was this page helpful?

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *