종우의 컴퓨터 공간
Window Objects 본문
Alert
window.alert('Hello World'); //usually we skip 'window.'
Prompt
const input = prompt();
alert(input);
- prompt 창을 띄우며 그 곳에 error message를 입력할 수 있다.
Confirm
if(confirm('Are you sure')) {
console.log('YES');
} else {
console.log('NO');
}
- used before when deleting something to confrim of the decision
Outter & Inner height and width
let height;
let width;
height = window.outerHeight;
width = window.outerWidth;
height = window.innerHeight;
width = window.innerWidth;
console.log(height);
console.log(width);
Scroll points
let val;
val = window.scrollY;
val = window.scrollX;
console.log(val);
- used when there is a scroll bar
- X is for the width, and Y is for the height
Location Object
let val;
val = window.location;
val = window.location.hostname;
val = window.location.port;
val = window.location.href;
val = window.location.search;
console.log(val);
- there are tons of inforamtion in array about port number, IPs, domain, address, etc.
Redirect
window.location.href = 'http://google.com';
- it redirects the browser to specifically mentioned http address
History Object
let val;
window.history.go(-1); // -1 means the recent page that I visited
val = window.history.length;
console.log(val);
- used when you want to get the browsing history of currently opened browser
- 'go' method takes a parameter of a negative number which takes back to the sites that I have visited starting from -1, -2, -3, ...
Navigator Object
let val;
val = window.navigator;
val = window.navigator.appName;
val = window.navigator.appVersion;
val = window.navigator.userAgent;
val = window.navigator.platform; //yields Win32 for Windows
val = window.navigator.language;
console.log(val);
- there are tons of information in array about the browser
'자바 스크립트 (JavaScript) > JavaScript Language Fundamentals' 카테고리의 다른 글
General loops (0) | 2021.07.30 |
---|---|
Function Declarations & Expressions (0) | 2021.07.28 |
Switch Statement (0) | 2021.07.28 |
If Statements & Comparison Operators (0) | 2021.07.25 |
Dates & Times (0) | 2021.07.25 |