-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript15.html
More file actions
185 lines (149 loc) · 5.87 KB
/
JavaScript15.html
File metadata and controls
185 lines (149 loc) · 5.87 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html lang='ko'>
<head>
<title>window 객체</title>
<style>
.area {
background: lgithgray;
border: 1px solid black;
width: 300px;
height: 100px;
font-size: 50px;
color: red;
}
.area-big {
background: lightgray;
border: 1px solid black;
height: 300px;
}
</style>
</head>
<body>
<h1>window 객체</h1>
<p>window 객체는 자바스크립트의 최상위 객체이며 BOM과 DOM으로 나뉜다.</p>
<p>BOM(Browser Object Model) : location객체, navigator객체, history객체, screen객체</p>
<p>DOM(Document Object Model) : document객체</p>
<h3>window 객체</h3>
<p>브라우저 창에 대한 설정을 하는 객체</p>
<button onclick="test1();">네이버</button>
<button onclick="test2();">다음</button>
<script>
function test1() {
// window.open();
// window.open('주소', '이름 또는 open방식','형태');로 작성한다.
window.open('http://www.naver.com', '네이버', 'location=0,resizable=0, menubar=0,status=0,toolbar=0', false);
}
function test2() {
window.open("http://www.daum.net", "location=no", false);
}
</script>
<br>
<h3>window객체의 timer메소드</h3>
<h4>setTimeout()</h4>
<button onclick="test3();">실행확인</button>
<script>
function test3() {
var myWindow = window.open();
myWindow.alert('3초 후에 이 페이지는 종료됩니다.');
window.setTimeout(function () {
myWindow.close();
}, 3000);
}
</script>
<br>
<h4>setInterval()</h4>
<button onclick="test4()">실행확인</button>
<div id="area1" class="area"></div>
<script>
function test4() {
var area1 = document.getElementById("area1");
window.setInterval(function () {
var date = new Date();
area1.innerHTML = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}, 1000);
}
</script>
<br>
<h4>clearInterval()</h4>
<button onclick="test5()">실행확인</button>
<div id="area2" class="area"></div>
<script>
function test5() {
var area2 = document.getElementById("area2");
var count = 10;
var intervalID = window.setInterval(function () {
area2.innerHTML = "countdown : " + count--;
setTimeout(function () {
clearInterval(); // 위에 setInterval이 종료됨
area2.innerHTML = "종료 !";
}, 10000)
}, 1000);
}
</script>
<hr>
<h3>screen 객체</h3>
<p>웹 브라우저 화면이 아닌 운영체제 화면의 속성을 가지는 객체이다</p>
<button onclick="test6();">실행확인</button>
<script>
function test6() {
var width = screen.width;
var height = screen.height;
child = window.open("", "", "width=800, height=500");
child.resizeTo(width, height);
setInterval(function () {
child.resizeBy(-20, -20);
child.moveBy(10, 10);
}, 500);
console.log("화면높이 : " + screen.height);
console.log("화면 너비 : " + screen.width);
console.log("실제 화면에서 사용 가능한 너비 : " + screen.availWidth);
console.log("실제 화면에서 사용 가능한 높이 : " + screen.availHeight);
console.log("사용 가능한 색상수 : " + screen.colorDepth);
console.log("한픽셀당 비트수 : " + screen.pixelDepth);
}
</script>
<hr>
<h3>location 객체</h3>
<p>브라우저 주소 표시줄과 관련된 객체이다.</p>
<button onclick="test7();">실행확인</button>
<div id="area3" class="area-big"></div>
<script>
function test7() {
var area3 = document.getElementById("area3");
for (var key in location) {
area3.innerHTML += (key + " : " + location[key] + "<br>");
}
}
</script>
<br>
<button onclick="location.href = 'http://www.naver.com'">네이버로 이동</button>
<button onclick="location = location">새로고침</button>
<button onclick="location.href = location.href">새로고침</button>
<button onclick = "location.reload()">새로고침</button>
<br><br>
<button onclick="location.assign('http://google.com')">구글로 이동</button>
<!-- replace ★★★★★ -->
<button onclick="location.replace('http://google.com')">구글로 이동(뒤로가기X)</button>
<hr>
<h3>navigator 객체</h3>
<p>웹 페이지를 실행하고 있는 브라우저에 대한 정보를 가지고 있는 객체</p>
<button onclick ="test8();">실행확인</button>
<div id = "area8" class = "area-big"></div>
<script>
function test8(){
var area8 = document.getElementById("area8");
var str = "";
for(var key in navigator){
str += (key + " : " + navigator[key] + "\n");
}
alert(str);
area8.innerHTML += "브라우저의 코드명 : " + navigator.appCodeName + "<br>";
area8.innerHTML += "브라우저의 이름 : " + navigator.appName + "<br>";
area8.innerHTML += "브라우저의 전체 정보 : " + navigator.userAgent + "<br>";
area8.innerHTML += "브라우저의 언어 : " + navigator.language + "<br>";
area8.innerHTML += "브라우저의 운영체제 : " + navigator.platform + "<br>";
}
</script>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>