1BOM(Browser Object Model)
(1) window 객체
- 웹 브라우저의 창을 나타내는 객체
- 자바스크립트의 모든 객체, 전역변수, 전역함수들은
자동으로 window 객체의 프로퍼티가 됨
1) window.onload = function(){
}
2) window.open()
- 새로운 브라우저 창을 여는 메서드
- 내 페이지에, 새 페이지에, 부모 페이지에, 자식 페이지에
- 기본 사용법
var 객체명 = window.open(url, name, spec)
url : 이동할 주소
name : _blank(새창), _self(현재 페이지)
_parent(부모 프레임), _child(자식 프레임)
spec : 창의 크기, 스크롤가능여부, 리사이즈가능여부
☆ Code
<!doctype html>
<html>
<head>
<title>Window Open</title>
</head>
<body>
<h1>New Windows Open</h1>
<hr>
<button id="newwin">New</button>
<button id="here">Here</button>
<button id="loc">Location</button>
</body>
<script>
var newwin = document.getElementById("newwin");
var here = document.getElementById("here");
var loc = document.getElementById("loc");
// newwin.addEventListener("click", function(){ })
newwin.onclick = function(){
alert("newwin clicked");
window.open("http://www.pixabay.com",
"_blank",
"width=1200, height=900"
);
}
here.onclick = function(){
window.open("http://www.nytimes.com",
"_self"
);
}
loc.onclick = function(){
var amt = 100;
location.href = "http://localhost:5501?amt=" + amt;
}
</script>
</html>
'JavaScript' 카테고리의 다른 글
JS 카카오맵 API 사용하기 (0) | 2025.01.05 |
---|---|
JS 배너 (0) | 2024.12.04 |
JS dom (0) | 2024.12.03 |
JS 콜백 (0) | 2024.12.02 |
JS json (0) | 2024.12.01 |