一、引入BOM程式設計:
1、javascript組成部分:
1)EMCAScript(基本文法)
2)BOM( Browser Object Model) 浏覽器對象模型.
浏覽器對象模型中把浏覽器的各個部分都是用了一個對象進行描述,如果我們要操作浏覽器的一些屬性,我們就可以通過浏覽器對象模型的對象進行操作。
3)DOM。
之前已經講過了EMCAScript(基本文法),接下來說說BOM程式設計。
2、浏覽器對象:
1)window 代表了一個新開的視窗
2)location 代表了位址欄對象。
3)screen 代表了整個螢幕的對象
學習這部分内容就要查閱DHTML文檔!
二、window對象:
1、常用的方法:
1)open() 打開一個新的視窗。
2)resizeTo() 将視窗的大小更改為指定的寬度和高度值。
3)moveBy() 相對于原來的視窗移動指定的x、y值。
4)moveTo() 将視窗左上角的螢幕位置移動到指定的 x 和 y 位置。
<!--ad.html-->
<!DOCTYPE html>
<html>
<head>
<title>ad.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css" target="_blank" rel="external nofollow" >-->
</head>
<body>
<marquee>我是廣告,我來了!!</marquee>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function showAd(){
window.open("ad.html","_blank","height=400px,width=400px,toolbar=no,location=no,top=200px");
//(屬性依次為:要打開的頁面,以建立頁面的形式高,寬,工具欄不顯示,位址欄不顯示,距頂部距離),參數不一定都要寫,幾個都可以
}
function small(){
window.resizeTo(,);//相對于原本視窗改變指定的大小。
}
function move(){
window.moveBy(,); // 相對于原來的視窗移動指定的x、y值,可以多次移動。
}
function move2(){
window.moveTo(,); // 相對于左上角位置移動x、y值,僅能移動一次。
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無标題文檔</title>
</head>
<body>
<input type="button" onclick="showAd()" value="下載下傳電影"/>
<input type="button" onclick="small()" value="變小"/>
<input type="button" onclick="move()" value="moveBy"/>
<input type="button" onclick="move2()" value="moveTo"/>
</body>
</html>
5)setInterval() 每經過指定毫秒值後就會執行指定的代碼。
6)clearInterval() 根據一個任務的ID取消定時任務。
7)setTimeout() 經過指定毫秒值後執行一次指定的代碼。
<script type="text/javascript">
function showAd(){
open("ad.html","_blank","height=400px,width=400px,toolbar=no,location=no,top=200px");
setTimeout("showAd()",);
var id =setInterval("showAd()",);
function clearTest(){
clearInterval(id);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無标題文檔</title>
</head>
<body>
<input type="button" onclick="showAd()" value="下載下傳電影"/>
<input type="button" onclick="clearTest()" value="取消定時任務"/>
</body>
</html>
2、注意: 使用window對象的任何屬性與方法時都可以省略window對象不寫。