成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術文章
文章詳情頁

JavaScript中的location、history、navigator對象實例介紹

瀏覽:2日期:2022-06-10 14:58:02

1.location

//地址欄上#及后面的內容
console.log(window.location.hash);
//主機名及端口號
console.log(window.location.host);
//主機名
console.log(window.location.hostname);
//文件的路徑---相對路徑
console.log(window.location.pathname);
//端口號
console.log(window.location.port);
//協議
console.log(window.location.protocol);
//搜索的內容
console.log(window.location.search);
//設置跳轉的頁面的地址
location.;//屬性----------------->必須記住
location.assign("http://www.jb51.net");//方法
//重新加載--刷新
location.reload();
//沒有歷史記錄
location.replace("http://www.jb51.net");

2.history

<body>
<input type="button" value="跳過去" id="btn1"/>
<input type="button" value="前進" id="btn2"/>
<script>
    //跳轉的
    document.getElementById("btn1").onclick = function () {
window.location.;
    };
    //前進
    document.getElementById("btn2").onclick = function () {
window.history.forward();
    };
</script>
</body>

歷史記錄的后退和前進 history: back()后退 forward()前進 

3.navigator

<script>
    //通過userAgent可以判斷用戶瀏覽器的類型
    console.log(window.navigator.userAgent);
    //通過platform可以判斷瀏覽器所在的系統平臺類型.
    console.log(window.navigator.platform);
</script>

到此這篇關于JavaScript中的location、history、navigator對象實例介紹的文章就介紹到這了,更多相關js location、history、navigator內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: JavaScript