BOM(Browser Object Mode) : 브라우저에서 지원해주는 것들
window 객체
document, navigator, location, screan, histroy
open, alert, prompt, setinterval
Ex_ popup
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
function popup() {
window.open("popup.html", "popup1", "width=300px, height=400px");
}
</script>
</head>
<body>
<button onclick="popup();">버튼</button>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<a href="http://www.naver.com">
<img src="images/popup.jpg" alt="팝업 페이지"/></a>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
function popup() {
window.open("popup.html", "popup1", "width=300px, height=400px");
}
function navigat() {
document.write("전체정보 : " +navigator.userAgent+"<br />");
}
</script>
</head>
<body>
<button onclick="popup();">버튼</button>
<button onclick="navigat();">navigator</button>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
var myAgent=navigator.userAgent.toLowerCase();
var mobile=["iphone","ipod","android","blackberry","window ce","nokia",
"webos","opera mini","sonyericsson","opera mobi","iemobile"];
for(var i=0; i<mobile.length; i++){
if(myAgent.indexOf(mobile[i]) >= 0){
location.href="http://m.naver.com";
break;
}
}
</script>
</head>
<body>
<!-- -->
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>첫 페이지</h1>
<a href="test10.html">두 번째 페이지 이동</a>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>두 번째 페이지</h1>
<p><a href="test11.html">마지막 페이지로 이동</a></p>
<p><button onclick="javascript:history.back();">이전 페이지로 이동</button></p>
<p><button onclick="javascript:history.go(1);">다음 페이지로 이동</button></p>
<p><button onclick="javascript:history.forward();">forward 페이지로 이동</button></p>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>마지막 페이지</h1>
<button onclick="javascript:history.back();">이전 페이지로 이동1</button>
<button onclick="javascript:history.go(-1);">이전 페이지로 이동2</button>
<button onclick="javascript:history.go(-2);">첫 페이지로 이동</button>
</body>
</html>
흐름제어 이용 3가지
html : a태그
javascript : location.href, histroy
Ex_ prompt
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
function alt() {
alert("알림 창입니다.");
}
function conf() {
if(confirm("장바구니로 이동하시겠습니까?")){ // true 또는 false만 전달
location.href="http://naver.com";
}
}
function promp() {
var name=prompt("당신의 이름을 입력해주세요.");
document.write(name);
}
</script>
</head>
<body>
<button onclick="alt();">경고창</button>
<button onclick="conf();">확인</button>
<button onclick="promp();">prompt</button>
</body>
</html>