文章詳情頁
JavaScript中的location、history、navigator對象實(shí)例介紹
瀏覽:23日期:2022-06-10 14:58:02
1.location
//地址欄上#及后面的內(nèi)容
console.log(window.location.hash);
//主機(jī)名及端口號
console.log(window.location.host);
//主機(jī)名
console.log(window.location.hostname);
//文件的路徑---相對路徑
console.log(window.location.pathname);
//端口號
console.log(window.location.port);
//協(xié)議
console.log(window.location.protocol);
//搜索的內(nèi)容
console.log(window.location.search);
//設(shè)置跳轉(zhuǎn)的頁面的地址
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="前進(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)平臺類型.
console.log(window.navigator.platform);
</script>
到此這篇關(guān)于JavaScript中的location、history、navigator對象實(shí)例介紹的文章就介紹到這了,更多相關(guān)js location、history、navigator內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!
標(biāo)簽:
JavaScript
排行榜

網(wǎng)公網(wǎng)安備