최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

데스크탑, 모바일, 태블릿으로 각 디바이스에 맞춰 페이지 처리한것.

 

결과 값으로 나온것을 switch으로 나누어서 location.href 로 띄웠다. 

소스응용 : http://ultteky.egloos.com/

 

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<script>
var EiwafDevice = {

 TYPE_DESKTOP: "desktop",

 TYPE_PHONE: "phone",

 TYPE_TABLET: "tablet",

 agent: {

  mobile: (/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i.test(window.navigator.userAgent)),

  tablet: (/iPad|tablet/i.test(window.navigator.userAgent))

 },

 detect: function () {

  if (this.type) {

   return;

  }

  if (this.agent.mobile) {

   var userAgent = navigator.userAgent.toLowerCase();

   if (userAgent.search("android") > -1) {

    if (userAgent.search("mobile") == -1) {

     this.type = this.TYPE_TABLET;

    }

   }

   if (!this.type) {

    this.type = this.TYPE_PHONE;

   }

  }

  if (this.agent.tablet) {

   this.type = this.TYPE_TABLET;

  }

  if (!this.type) {

   this.type = this.TYPE_DESKTOP;

  }

 }

};




EiwafDevice.detect();

EiwafDevice.detect();

EiwafDevice.detect();

document.write("<br>결과 : " + EiwafDevice.type);

switch (EiwafDevice.type)
{
 case "desktop":
  location.href="web.html"
 break;
 case "phone":
  location.href="mobile.html"
 break;
 case "tablet":
  location.href="tablet.html"
 break;
}

</script>
</body>
</html>

 

댓글