>  기사  >  웹 프론트엔드  >  JavaScript 웹 프로그래밍------브라우저 개체 모델(BOM)

JavaScript 웹 프로그래밍------브라우저 개체 모델(BOM)

黄舟
黄舟원래의
2016-12-30 16:33:591132검색

브라우저 개체
모델: BOM)

주로 창 개체에 대해 이야기합니다. 브라우저에서 열려 있는 창을 나타냅니다.

BOM 기능

브라우저 창 자체, 검색 기록 등 브라우저의 다양한 기능 구성 요소에 접근할 수 있는 작업 방법을 제공합니다.

2. 창 내 이벤트

3. 이벤트(브라우저 수명 주기): onload, onunload, onbeforeunload (단어에서 의미를 볼 수 있고, 다른 이벤트도 있으며, 도움말 문서를 확인할 수 있습니다.)

<!DOCTYPE html> 

<html> 

<head> 

<title>bom_window_event.html</title> 

</head> 



<body> 



<script type="text/javascript"> 

//事件注册 

onload=function(){ 

//alert("onload..."); 

window.open("ad.html","_blank","height=300,width=300,status=no,toolbar=no,menubar=no,location=no"); 

} 

/* 

onunload=function(){ 

alert("onunload..."); 

} 

onbeforeunload=function(){ 

alert("onbeforeunload..."); 

} 

*/ 

</script> 



</body> 

</html>

세 가지, 창의 메서드

<!DOCTYPE html> 

<html> 

<head> 

<title>bom_window_method.html</title> 

</head> 



<body> 



<script type="text/javascript" src="print.js"> 

</script> 



<script type="text/javascript"> 

//window中的方法 

function f1(){ 

var b = confirm("你确定要执行吗?"); 

alert("b="+b); 

} 



var id1,id2; 

function f2(){ 

// id1 = setTimeout("alert(&#39;time out...&#39;)" , 3000);//经过指定毫秒值后计算一个表达式----定时器 

id2 = setInterval("alert(&#39;time out...&#39;)" , 3000);//每经过指定毫秒值后计算一个表达式----定时器 

} 



function f3(){ 

//clearTimeout(id1); 

clearInterval(id2);//清除定时器 

} 



function f4(){ 

//moveBy(10,10);//浏览器窗口----相对移动,向右下角移动(水平与垂直方向分别移动10像素) 

//moveTo(40,40); 

//窗口抖动 

for(var x=0;x<10;x++){ 

moveBy(20,0); 

moveBy(0,20); 

moveBy(-20,0); 

moveBy(0,-20); 

} 

} 



</script> 



<input type="button" value="演示window中的方法1--确认提示窗口" onclick="f1()" /><br/> 

<input type="button" value="演示window中的方法2--定时器1" onclick="f2()" /><br/> 

<input type="button" value="演示window中的方法2--定时器2" onclick="f3()" /><br/> 

<input type="button" value="演示window中的方法3--move" onclick="f4()" /><br/> 





</body> 

</html>

4. 창의 개체

1. 창의 Navigator 개체 ---- 브라우저 정보

function windowNavigatorShow(){ 

var name = window.navigator.appName; 

//var version = window.navigator.appVersion; 

var version = navigator.appVersion;//window对象是默认的,可以省略不写 

println("name:"+name+",version:"+version); 

}

2, 창의 위치 개체-- --브라우저 주소 표시줄

<span style="font-weight: normal;">function windowObj4(){  
            //获取属性  
            var pro = window.location.protocol; //window可省略  
            //alert(pro);  
            var text = location.href;  
            alert(text);  
              
            location.href="http://www.baidu.com.cn";//1
	    location.href ="5a.html";//2
	    //上两句1和2处可以对目前所处的地址进行更改,这就是在浏览器中浏览到某些东西时突然会跳到其他页面去的原理,如1会自动跳转到百度
}</span>

5a.html

<html>
  <head>
    <title>aa</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
  
  <body>
  	<script type="text/javascript">
  		function windowObjDemo(){
			history.back();
		}  	
  	</script>
    <input type="button" value="演示window中的对象" onclick="windowObjDemo()" />
  </body>
</html>

3. 창의 기록 개체----브라우저가 URL 정보를 탐색했습니다

방법:

back 히스토리 목록에서 이전 URL을 불러옵니다.

forward 기록 목록에서 다음 URL을 로드합니다.

이동 기록 목록에서 URL을 로드합니다.

<input type="button" value="演示window中的对象3--history,后退" onclick="history.back()" />


위 내용은 자바스크립트 웹 프로그래밍 내용입니다------브라우저 객체 모델(BOM) 관련 내용을 더 원하시면 결제해주세요. PHP 중국어 홈페이지(www.php.cn)를 주목해주세요!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.