bom:即broswer object model(瀏覽器對象模型),由五個對象組成:
Window:對象表示瀏覽器中打開的窗口 最頂層對象.
Navigator :瀏覽器對象.
Screen: 屏幕對象
History:瀏覽器歷史對象
Location:地址對象.
<!DOCTYPE html> <html> <head> <title>JavaScript BOM對象</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" > //navigator對象舉例,返回瀏覽器的名稱和瀏覽器的平台和版本信息。 document.write(navigator.appName+" "+navigator.appVersion); document.write("<hr/>"); //screen對象舉例,返回顯示屏幕的高度(除 Windows 任務欄之外)和顯示屏幕的寬度 (除 Windows 任務欄之外)。 document.write(screen.availHeight+" "+screen.availWidth); document.write("<hr/>"); //location對象舉例 function href1() { location.href = "https://www.baidu.com";//跳轉到百度 } function up() { history.back();//可用history.go(-1)代替 } //history對象舉例 function next() { history.forward();//可用history.go(1)代替,history.go(2)相當於點擊兩次下一頁 } //window對象舉例(window可省略,如window.alert()可替換為alert()) window.setTimeout("document.write('setTimeout');", 2000);//兩秒后輸出一個setTimeout單詞(只輸出一次) window.setInterval("document.write('<hr/>');", 2000);//每兩秒輸出一個下划線 </script> </head> <body> <input type="button" value="跳轉" onclick="href1();"/> <input type="button" value="上一頁" onclick="up();"/> <input type="button" value="下一頁" onclick="next();"/> </body> </html>
運行頁面: