JS之BOM的几个对象

Posted hzdwwzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS之BOM的几个对象相关的知识,希望对你有一定的参考价值。

location对象

浏览器的地址栏对象

//对象中的属性和方法
//location对象
//console.log(window.location);
//地址栏上#及后面的内容
//console.log(window.location.hash);
//主机名及端口号
//console.log(window.location.host);
//主机名
//console.log(window.location.hostname);
//文件的路径---相对路径
//onsole.log(window.location.pathname);
////端口号
//console.log(window.location.port);
//协议
//console.log(window.location.protocol);
//搜索的内容
//onsole.log(window.location.search);

location其他的属性和方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="button" id="btn" value="按钮"/>
<script>
    document.getElementById("btn").onclick = function () {
        location.href="http://www.baidu.com";//跳转到页面的属性,浏览器有后退
        //location.assign("http://www.baidu.com");//跳转到页面的方法,浏览器有后退
        // location.reload();//重新加载--刷新
        //location.replace("http://www.jd.com");//替换,浏览器不能后退
    };
</script>
</body>
</html>
//通过platform属性可以判断浏览器所在的系统平台类型.
//console.log(window.navigator.platform);

定时器

<script>
//setInterval函数返回timeId
  var timeId = setInterval(function () {
    alert("hello");//每隔一秒弹框
  }, 1000);
  document.getElementById("btn").onclick = function () {
    //点击按钮,停止定时器
    //参数:要清理的定时的id的值
    window.clearInterval(timeId);
  };
</script>

以上是关于JS之BOM的几个对象的主要内容,如果未能解决你的问题,请参考以下文章

JS之BOM与DOM

JS 总结之关于 this 应该知道的几个点

web前端开发需要掌握的几个必备技术

JS学习笔记8之 BOM-浏览器对象模型

javascript之BOM对象(二location对象)

JS之BOM