JavaScript中的location、history、navigator對(duì)象實(shí)例介紹
1.location
//地址欄上#及后面的內(nèi)容 console.log(window.location.hash); //主機(jī)名及端口號(hào) console.log(window.location.host); //主機(jī)名 console.log(window.location.hostname); //文件的路徑---相對(duì)路徑 console.log(window.location.pathname); //端口號(hào) console.log(window.location.port); //協(xié)議 console.log(window.location.protocol); //搜索的內(nèi)容 console.log(window.location.search); //設(shè)置跳轉(zhuǎn)的頁面的地址 location.href = "http://chabaoo.cn";//屬性----------------->必須記住 location.assign("http://chabaoo.cn");//方法 //重新加載--刷新 location.reload(); //沒有歷史記錄 location.replace("http://chabaoo.cn");
2.history
<body> <input type="button" value="跳過去" id="btn1"/> <input type="button" value="前進(jìn)" id="btn2"/> <script> //跳轉(zhuǎn)的 document.getElementById("btn1").onclick = function () { window.location.; }; //前進(jìn) document.getElementById("btn2").onclick = function () { window.history.forward(); }; </script> </body>
歷史記錄的后退和前進(jìn) history: back()后退 forward()前進(jìn)
3.navigator
<script> //通過userAgent可以判斷用戶瀏覽器的類型 console.log(window.navigator.userAgent); //通過platform可以判斷瀏覽器所在的系統(tǒng)平臺(tái)類型. console.log(window.navigator.platform); </script>
到此這篇關(guān)于JavaScript中的location、history、navigator對(duì)象實(shí)例介紹的文章就介紹到這了,更多相關(guān)js location、history、navigator內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript實(shí)現(xiàn)QueryString獲取GET參數(shù)的方法
本文為大家詳細(xì)介紹下如何通過JavaScript實(shí)現(xiàn)QueryString獲取GET參數(shù),具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-07-07KnockoutJS 3.X API 第四章之表單textInput、hasFocus、checked綁定
這篇文章主要介紹了KnockoutJS 3.X API 第四章之表單textInput、hasFocus、checked綁定的相關(guān)資料,需要的朋友可以參考下2016-10-10基于javascript實(shí)現(xiàn)最簡單的選項(xiàng)卡切換效果
這篇文章主要介紹了基于javascript實(shí)現(xiàn)最簡單的選項(xiàng)卡切換效果的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05