window.navigator 객체는 사용자의 브라우저와 operation system 정보 뿐아니라, 다양한 메소드와 프로퍼티를 갖고 있습니다. 주로 앞의 "window"는 생략하고 사용 합니다.
geolocation 속성은 사용자의 위치 정보를 확인하는데 사용되는 Geolocation object 를 반환합니다.
geolocation 속성은 read-only 입니다.
geolocation property 는 오직 secure contexts (HTTPS) 에서만 사용 가능합니다.
geolocation 속성은 오직 사용자가 승인을 해야만 사용가능 합니다.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
console.log("Latitude: " + position.coords.latitude);
console.log("Longitude: " + position.coords.longitude);
}, function(error) {
console.error("Error Code = " + error.code + " - " + error.message);
});
} else {
console.log("Geolocation is not supported by this browser.");
}
language 속성은 브라우저 설정 언어를 반환하며, read-only 입니다.
let language = navigator.language; //ko-KR
let platform = navigator.platform;
사용자의 브라우저에서 Java 가 사용가능 한지 점검
if (navigator.javaEnabled()) {
console.log("Java is enabled");
} else {
console.log("Java is not enabled");
}
navigator.getBattery().then(function(battery) {
console.log("Battery level: " + battery.level * 100 + "%"); // 100%
console.log("Battery charging: " + battery.charging); // true or false
});
이 메소드는 사용자에게 미디어(예: 오디오, 비디오)가 포함된 MediaStream을 생성/사용 권한을 묻는 메시지를 표시합니다.
navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(function(stream) {
const video = document.querySelector('video');
video.srcObject = stream;
})
.catch(function(err) {
console.log("Error: " + err);
});
이 메서드는 컴퓨터에 연결된 모든 VR 디스플레이를 나타내는 VRDisplay 배열로 해결되는 Promise를 반환합니다.
navigator.getVRDisplays().then(function(displays) {
if (displays.length > 0) {
console.log("VR displays found: ", displays);
} else {
console.log("No VR displays found");
}
});
const url = "https://example.com/log";
const data = new Blob(["User action data"], {type: 'text/plain'});
navigator.sendBeacon(url, data);
// Vibrate for 1 second
navigator.vibrate(1000);
// Vibrate in a pattern: vibrate for 1 second, pause for half a second, vibrate for 1 second
navigator.vibrate([1000, 500, 1000]);
if (navigator.share) {
navigator.share({
title: 'Web Fundamentals',
text: 'Check out this amazing site!',
url: 'https://example.com'
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing:', error));
} else {
console.log('Web Share API not supported');
}
.gitignore, .gitattributes (1) | 2024.09.16 |
---|---|
경도, 위도, Longitude, Latitude (0) | 2024.09.12 |
.json 과 .json5 의 차이점 (1) | 2024.06.03 |
parcel - webapp 설치 (0) | 2024.05.30 |
webpack 개념 (0) | 2024.05.30 |