1. 클라이언트 객체
[1]window의 메서드(window. 생략 가능)
- window.alert() : 경고창
- widow.prompt() : 입력창
- window.confirm() : 선택창
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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>클라이언트 객체 : 윈도우</title>
<script type="text/javascript">
window.alert('경고창');
var season = window.prompt('좋아하는 계절은?');
document.write('좋아하는계절은 '+season+'입니다.<br>');
var choice = window.confirm('야근을 하겠습니까?');
//확인 true , 취소 false 반환
//x아이콘 클릭 시 false 처리
if(choice){ //choice가 true이면
document.write('야근 확정<br>');
}else {
document.write('야근 취소<br>');
}
</script>
</head>
<body>
</body>
</html>
|
cs |
[2]window.open(url,새창이름,옵션) : 새 창을 열어주는 기능
width : 새 윈도우의 넓이
height : 새 윈도우의 높이
location : 주소 입력창 유무
menubar : 메뉴의 유무
resizable : 화면 크기 조절 기능 여부
status : 상태 표시줄의 유무
toolbar : 툴바 유무
scrollbars : 스크롤바 유무
window.close(); : 창을 닫아주는 기능
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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>클라이언트 객체 : 윈도우</title>
<script type="text/javascript">
var win;
//새창 열기
function winOpen(){
// URL 새 창 이름 옵션
win = window.open('https://www.naver.com','child','toolbar=no,location=no,menubar=no,resizable=no,scrollbars=no,width=400,height=300');
}
//열려있는 창 닫기
function winClose(){
win.close();
}
</script>
</head>
<body>
<input type="button" value="창 열기" onclick="winOpen();"><br>
<input type="button" value="창 닫기" onclick="winClose();">
</body>
</html>
|
cs |
2. settimeout / setinterval
- settimeout : 일정 시간 후에 함수를 한번 실행
- setinterval : 일정 시간 마다 함수를 반복해서 실행
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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>setTimeout</title>
<script type="text/javascript">
/*
setTimeout(function, milliseond) : 일정 시간 후에 함수를 한번 실행
setInterval(function,millisecond) : 일정 시간 마다 함수를 반복해서 실행
속성
onload : 윈도우가 로드될 때 호출(전체 페이지가 다 열린 후 실행)
*/
//윈도우가 로드될 때 호출
window.onload = function(){
alert ('경고창을 닫고 3초 후 이 페이지는 종료됩니다.');
//3초 후에 함수를 실행합니다.
window.setTimeout(function(){
window.close(); //현재 창 닫기
},3000);
};
</script>
</head>
<body>
</body>
</html>
|
cs |
'프로그래밍 > 자바스크립트' 카테고리의 다른 글
[자바스크립트]내장 객체 : Array, Math (0) | 2021.07.27 |
---|---|
[자바스크립트]클라이언트 객체 : location, history (0) | 2021.07.26 |
[자바스크립트]배열 : 요소 정렬 / 배열 메서드(join,slice,concat,pop,push) (0) | 2021.07.26 |
[자바스크립트] 배열 : 배열 생성, for in문, 요소 추가/삭제 (0) | 2021.07.26 |
[자바스크립트]내장 함수 : eval() (0) | 2021.07.26 |