JS BOM篇(二)location对象与history对象

news/2024/7/10 2:00:53 标签: javascript, js, vue, 前端

location 对象

js">location 是最有用的对象之一。
1.提供了与当前窗口中加载的文档有关的信息,
2.提供了导航功能。
3.即是window对象的属性,也是document对象的属性。
	即(window.location = document.location)
  • 属性列表
属性名例子说明
hash“#content”返回URl中的hash(#号后跟0或多个字符),如果不包括散列,则返回空字符
host“www.jsk.com:80”返回服务器名称和端口号(如果有)
hostname“www.jsk.com”返回不带端口号的服务器名称
href“http://www.jsk.com:80/md?articleId=1”返回当前加载页面的完整URL。location对象的toString()方法也返回这个值
pathname“/md”返回URL中的目录和文件名
port“8080”返回端口号,如果没有返回空
protocol“http:”返回页面使用的协议
search“?articleId=1”返回URL的查询字符串,以? 开头
  • 查询字符串参数
js">//查询字符串参数
  function getQueryArr(){
    let qs= location.search.length>0? location.search.slice(1):''
    let args = {},
    item = null;
    
    arr = qs.length>0?qs.split('&'):[]
    for (let i = 0; i < arr.length; i++) {
      item = arr[i].split('=')
      let name = decodeURIComponent(item[0])
      let value = decodeURIComponent(item[1])
      if (name.length) {
        args[name] = value
      }
    }
    return args
  }
  console.log(getQueryArr());
  
  • 方法
方法名例子说明
assignlocation.assign(“http://www.jsk.com”)立即打开并生成一条记录
replacelocation.replace(“http://www.jsk.com”)不会在历史记录中生成新记录,不能回到前一个页面
reloadlocation.reload()重新加载(有可能能从缓存中加载),如果传递参数true 从服务器重新加载

注意
以下三种方式相同

js">location.assign('http://www.jsk.com')
location.href = 'http://www.jsk.com'
window.location = 'http://www.jsk.com'

history对象

  • 方法
方法名例子说明
gohistory.go(-1)正数 向前n页 负数 向后退n页 如果是string,寻找最近的含有相似字符的页面地址
forwardhistory.forward()前进一页
backhistory.back()后退一页

vue 的路由跳转以及传参由这些api实现

navigator

主要用来识别客户端浏览器的类型
有userAgent 等重要属性,以后补上


http://www.niftyadmin.cn/n/1852492.html

相关文章

1.3 Linux分区类型

1.主分区最多只能有4个。 2.扩展分区&#xff1a; 最多只能有一个&#xff1b; 主分区加扩展分区最多只能有4个&#xff1b; 扩展分区只能包含逻辑分区&#xff0c;不能写数据。 3.格式化目的&#xff1a; 写入文件系统&#xff1b;清除数据&#xff1b;划出文件分配表&#xf…

JS DOM篇(一)

Node类型 DOM1级定义了一个Node接口&#xff0c;节点类型定义了12个常数值常量来表示&#xff08;用nodeType区分&#xff09; 开发人员最常用的就是元素节点和文本节点 nodeName 和 nodeValue属性 if(someNode.nodeType 1){value someNode.nodeName //nodeName是元素的标…

Game Creators: Threading for Games (英文)

获取视频链接:[url]http://softwarevideos-zho.intel.com/index.php?category_id4&vid_id70&langZH-CN[/url]下载该视频访问英特尔 移动软件开发社区Lee Bamber, CEO of Game Creators, talks about the performance gains they made through threading their game ar…

Oracle表字段的增加、删除、修改和重命名

本文主要是关于Oracle数据库表中字段的增加、删除、修改和重命名的操作。 增加字段语法&#xff1a;alter table tablename add (column datatype [default value][null/not null],….); 说明&#xff1a;alter table 表名 add (字段名 字段类型 默认值 是否为空); 例&#xff…

JS DOM篇(二)Element 类型

Element 类型 标签汇总&#xff08;省略,在html中总结&#xff09;操作属性方法 nodeName || tagName //访问元素的标签名 getAttribute(attrName) //获取属性 setAttribute(atrtName,attrVal) //设置属性创建元素 var odiv document.createElement(div) odiv.id myDiv …

Windows内存管理机密+揭穿内存优化工具的骗局

原文&#xff1a;The Memory-Optimization Hoax:RAM optimizers make false promises 作者&#xff1a;Mark Russinovich 译者&#xff1a;盆盆我们在浏览网页时&#xff0c;也许会经常看到一些弹出广告&#xff0c;例如“整理内存碎片、提升系统性能”、或者“大大减少系统和程…

go系列(3)- go框架beego以及redis的使用

这篇讲讲如何在beego框架使用redis。 golang中比较好用的第三方开源redisclient有&#xff1a; go-redis 源码地址&#xff1a;https://github.com/go-redis/redis文档地址&#xff1a;http://godoc.org/github.com/go-redis/redisredigo 源码地址&#xff1a;https://github.c…

(一) 多窗口打开单页面实现同步拖拽

step1 实现拖拽 css <style>*{margin: 0;padding: 0;}.box{width: 200px;height: 200px;background-color: #ae7000;cursor: pointer;text-align: center;line-height: 200px;position:absolute;} </style>html <body><div class"box">dr…