반응형

자바스크립트 개발 환경 Microsoft Visual Studio 2015 버전 HTML 기능 및 Chrome을 이용하고 있습니다.





이번에는 window.navigator 오브젝트에 대해 알아보려 한다.




navigator.cookieEnabled


쿠키 사용가능 여부를 판단한다.

가능하다면 True, 그게 아니라면 False를 리턴한다.




navigator.appName


브라우저의 이름을 리턴해준다.


아마 "Netscape"라고 나올 수 있는데 이는 IE11, Chrome, Firefox 및 Safari의 응용 프로그램 이름이다.




navigator.appCodeName


브라우저의 Code Name를 리턴해준다.



navigator.product


브라우저 엔진 product 이름을 반환해준다.


이 속성을 이용하기에 조심할 점은, 대부분 브라우저는 "Gecko"를 product name으로 반환해준다.



navigator.appVersion


브라우저에 대한 버전 정보를 리턴해준다.




navigator.userAgent


현재 사용자의 정보를 담고 있다. 이를 이용하여 모바일인지 pc인지 구분 할 수 있기도 하다.


아래는 userAgent를 쓸때의 주의해야 할 점을 명시해두고 있다.


Warning !!! 

The information from the navigator object can often be misleading, and should not be used to detect browser versions because:


Different browsers can use the same name

The navigator data can be changed by the browser owner

Some browsers misidentify themselves to bypass site tests

Browsers cannot report new operating systems, released later than the browser

(출처 :: https://www.w3schools.com/js/js_window_navigator.asp)



navigator.platform


브라우저 플랫폼(OS)를 리턴해준다.




navigator.language


브라우저의 언어를 리턴해준다.




navigator.online


브라우저가 현재 온라인 연결을 가지고 있는지 여부를 리턴해준다.



navigator.javaEnabled()


사용자가 브라우저의 Java 기능을 켜두었는지의 여부를 나타내는 부울값 리턴



이제 모든 기능을 적용한 코드를 한번 보자.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<body>
 
    <h1>JavaScript With Crocus</h1>
 
    <p>아래 버튼을 눌러보세요!</p>
    <button type="button" onclick="getInfo()"> << 클릭 >> </button>
    <p id="test"></p>
 
    <script>
        function getInfo() {
            var cookieEnabled = navigator.cookieEnabled;
            var appName = navigator.appName;
            var appCodeName = navigator.appCodeName;
            var product = navigator.product;
            var appVersion = navigator.appVersion;
            var userAgent = navigator.userAgent;
            var platform = navigator.platform;
            var language = navigator.language;
            var onLine = navigator.onLine;
            var javaEnabled = navigator.javaEnabled();
 
            document.getElementById("test").innerHTML =
                "cookieEnabled :: " + cookieEnabled + "<br>" + "<br>" +
                "appName :: " + appName + "<br>" + "<br>" +
                "appCodeName :: " + appCodeName + "<br>" + "<br>" +
                "product :: " + product + "<br>" + "<br>" +
                "appVersion :: " + appVersion + "<br>" + "<br>" +
                "userAgent :: " + userAgent + "<br>" + "<br>" +
                "platform :: " + platform + "<br>" + "<br>" +
                "language :: " + language + "<br>" + "<br>" +
                "onLine :: " + onLine + "<br>" + "<br>" +
                "javaEnabled :: " + javaEnabled + "<br>" + "<br>";
        }
     </script>
 
</body>
</html>
 
 
</body>
</html>
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus



클릭하시면 결과 화면을 확인 할 수 있습니다.












반응형