BOM(瀏覽器對象模型)


 1.screen對象。

       console.log(screen);
            console.log(window.screen);
            console.log(screen.width);
            console.log(screen.height);
            console.log(screen.availHeight);//可用高度=screen-height-底部任務欄高度
            console.log(screen.availWidth);//可用寬度

2.location對象。

       console.log(location);
            console.log(location.href);//完整的URL路徑
            console.log(location.protocol);//協議名
            console.log(location.hostname);//主機名
            console.log(location.port);//端口號
            console.log(location.host);//主機名+端口號
            console.log(location.pathname);//文件路徑
            console.log(location.search);//從?開始的參數部分
            console.log(location.hash);//從#開始的錨點部分

3.使用location進行頁面跳轉。

       function gotoBaidu(){//1
                location="http://www.baidu.com";
//                window.location.href="http://www.baidu.com";
            }

4.跳轉頁面,加載新頁面以后,可以點擊回退按鈕返回。

       function gotoBaiduByAssign(){//2
                location.assign("http://www.baidu.com");
            }

5.跳轉頁面,加載新頁面以后,沒有回退按鈕,無法返回。

       function gotoBaiduByReplace(){//3
                location.replace("http://www.baidu.com");
            }

6.刷新當前頁面。

①location.reload();刷新頁面,如果本地有緩存,將從緩存中讀取,相當於F5。
②location.reload(true);強制刷新,無論是否有緩存,都將請求后台加載最新數據,相當於Ctrl+F5。

       function reloadPage(){//4
                location.reload();//刷新
                location.reload(true);//重新加載頁面,強制刷新
            }

7.history。

       console.log(history);
            console.log(history.length);//用於記錄當前頁面跳轉的歷史頁面個數

8.點擊去前一頁,相當於瀏覽器的前進按鈕,點擊去后一頁,相當於瀏覽器的后退按鈕。

       function forward(){
                location.forward();
            }
            function back(){
                location.back(;)
            }

9.表示跳轉到瀏覽歷史的任意頁面。

  +1前面一頁,相當於location.forward();
  -1后面一頁,相當於location.back();
  0當前頁,刷新頁面history.go(2);//第二頁0刷新當前頁

       function go(){
                history.go(2);//第二頁0刷新當前頁
            }

10. navigator了解,返回關於瀏覽器的的各種信息。

       console.log(navigator);
            //檢測瀏覽器安裝的所有插件
            for(var i=0;i<navigator.plugins.length;i++){
                console.log(navigator.plugins[i].name);
            }

1.prompt():彈窗輸入
 alert():彈窗輸出
2.confirm("");帶確定、取消的提示框,分別返回true、false
3.close();關閉當前瀏覽器窗口。
4.open();打開一個新窗口
 參數一:新窗口的地址
 參數二:新窗口的名字
 參數三:新窗口的各種配置屬性
 width=600px,height=200px,top=10px;left=20px
5.setTimeout();延時器,表示延時多少ms執行一個函數。
 參數一:可以傳入匿名函數,也可以傳入函數名。
 參數二:延時毫秒數
 參數三~參數n:傳給回調函數的參數。
 setTimeout(function(num1,num2){},2000,"haha",123);
6.setInterval();定時器,表示每隔多少毫秒執行一遍,其他方法與setTimeout()完全相同。
7.clearInterval和clearTimeout():分別清楚定時器,延時器。
 聲明定時時,可以接受返回的ID,並將ID傳給clearInterval即可清除。

//定時器
            var num=0;
            var intervalID=setInterval(function(){
                num++;
                console.log(num);
            },1000);
            setTimeout(function(){
                clearInterval(intervalID);
            },5000);
            var num=0,sum=0;
            var intervalID=setInterval(function(){
                num++;
                console.log(num);
                if(num>9){
                    clearInterval(intervalID);
                }
            });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM