这篇文章主要介绍了JavaScript中的location、history、navigator对象实例介绍,需要的朋友可以参考下
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.href = "//www.mobange.com";//属性----------------->必须记住
location.assign("//www.mobange.com");//方法
//重新加载--刷新
location.reload();
//没有历史记录
location.replace("//www.mobange.com");
2.history
<body>
<input type="button" value="跳过去" id="btn1"/>
<input type="button" value="前进" id="btn2"/>
<script>
//跳转的
document.getElementById("btn1").onclick = function () {
window.location.href = "http://www.baidu.com";
};
//前进
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中的location、history、navigator对象实例介绍


基础教程推荐
猜你喜欢
- JavaScript垃圾回收机制(引用计数,标记清除,性能优 2022-08-31
- Ajax提交表单并接收json实例代码 2023-02-13
- 原生ajax瀑布流demo分享(必看篇) 2023-02-01
- 解决:layUI数据表格+简单查询 2022-12-16
- 纯javascript的ajax实现php异步提交表单的简单实例 2022-12-28
- 在IE中为abbr标签加样式 2022-10-16
- AJax 把拿到的后台数据在页面中渲染的实例 2023-02-22
- Unicode中的常用字母小结 2022-09-21
- ajax实现数据分页查询 2023-01-31
- 关于ajax异步访问数据的问题 2023-02-23