window.location 结构
| 属性 | 含义 | |
| protocol | 协议 | |
| hostname | 服务器的名字 | |
| port | 端口 | |
| pathname | URL中主机名后的部分 | |
| search | "?"后的部分,又称为查询字符串 | |
| hash | 返回"#"之后的内容 | |
| host | 等于hostname + port | |
| href | 当前页面的完整URL |
window.location和document.location互相等价的,可以交换使用
location的8个属性都是可读写的,但是只有href与hash的写才有意义。例如改变location.href会重新定位到一个URL,而修改location.hash会跳到当前页面中的anchor(<a id="name">或者<div id="id">等)名字的标记(如果有),而且页面不会被重新加载
注意
URL:http://b.a.com:88/index.php?name=kang&how=#when=2011#first
| search: | "?name=kang&how=" | 第一个"?"之后 |
| hash: | "#when=2011#first" | 第一个"#"之后的内容 |
search:"?name=kang&how="第一个"?"之后
hash:"#when=2011#first"第一个"#"之后的内容
方法
location.assign( url )
location.assign('http://www.baidu.com'); 等同于 window.location = 'http://www.baidu.com'
这种方式会讲新地址放到浏览器历史栈中,意味着转到新页面后“后退按钮”仍可以回到该页面。
location.replace( url )
与assign方法一样,但会从浏览器历史栈中删除本页面,也就是说跳转到新页面后“后退按钮”不能回到该页面。目前IE、Chrome只是简单的跳转,只有Firefox会删除本页面的历史记录。
location.reload( force )
重新载入当前页面。force为true时从服务器端重载;false则从浏览器缓存中重载,默认值false。
window.location 结构的更多相关文章
- JavaScript window.location对象
JavaScript window.location对象 示例 注意 方法 经常使用window.location,它的结构总是记不住,简单梳理下,方便以后查询. 示例 URL:http://b. ...
- 判断移动端跳转,从移动端来的不跳转。利用localStorage保存状态,window.location.pathname跳转不同的url
手机访问 www.yourdomain.com 跳转,从m.yourdomain.com来的不跳转. 访问www.yourdomain.com/category8, 跳转到m.yourdomain.c ...
- JavaScript window.location物
演示样例 注意 方法 常常使用window.location.它的结构总是记不住.简单梳理下.方便以后查询. 演示样例 URL:http://b.a.com:88/index.php? name=ka ...
- js 刷新页面window.location.reload();
Javascript刷新页面的几种方法:1 history.go(0)2 window.location.reload() window.location.reload(true) 3 ...
- window.top.location.href 和 window.location.href 的区别
"window.location.href"."location.href"是本页面跳转. "parent.location.href" 是 ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- window.location事件
一.最外层top跳转页面,适合用于iframe框架集 top.window.location.href("${pageContext.request.contextPath}/Login_g ...
- window.location.href 中文乱码问题。。。。
window.location.href 中文乱码问题.... 要解决此问题需要两次解码, 第一次解码: 是在页面中的js脚本中解码:window.location.href = "save ...
- window.open和window.location.href的几种用法
windows.open("URL","窗口名称","窗口外观设定"); <A href="javascript:windo ...
随机推荐
- highcharts去掉右下角highchart.com和右上角的图标(三个小横杆)
去除右下角highchart.com credits: { enabled:false } 去除右上角图标 exporting: { ...
- 《C#编程》
第一天做C#,第一个C#.2016-11-11,周五 1.是用windowFormApp编程的代码. 2.下面是ConsoleApp编程的代码 例题1.主要是声明变量,1>使用变量,赋值语句 2 ...
- LCA
2016.1.28 LCA,就是最近公共祖先,这里介绍倍增的算法. 首先我们要预处理,设f[i][j]为编号为i的节点的2j级祖先,所谓2j级祖先,就是从i节点开始往树的上层数2j个节点.如下图所示 ...
- Esfog_UnityShader教程_UnityShader语法实例浅析
距离上次首篇前言已经有一段时间了,一直比较忙,今天是周末不可以再拖了,经过我一段时间的考虑,我决定这一系列的教程会避免过于深入细节,一来可以避免一些同学被误导,二来会避免文章过于冗长难读, 三来可以让 ...
- 怎样安装Ubuntu操作系统
(转载自:http://jingyan.baidu.com/article/ff42efa9423991c19e22020d.html) 准备工作 1. 一台普通电脑(装没装操作系统无所谓),保证电脑 ...
- 一致性 hash 算法( consistent hashing )a
一致性 hash 算法( consistent hashing ) 张亮 consistent hashing 算法早在 1997 年就在论文 Consistent hashing and rando ...
- 开发android App干坏事(一)
最近都是在搞java,android的知识,前两天生日朋友和我聊到,有一个认识的人通过反编译android程序往里面插入广告积分墙赚了很大一笔钱,很短时间内赚了几十万,(为毛感觉这已经是扯淡篇了,转入 ...
- border:none;与border:0;的区别
border:none表示边框样式无,border:0表示边框宽度为0;当定义了border:none,即隐藏了边框的显示,实际就是边框宽度为0. 当定义边框时,必须定义边框的显示样式.因为边框默认样 ...
- 【Python】pip国内安装源
豆瓣安装源 pip install packages -i http://pypi.doubanio.com/simple --upgrade --trusted-host pypi.doubanio ...
- windows 下 gvim/vim lua支持问题,neocomplete等插件支持
此文是按照知乎 https://www.zhihu.com/question/29333426 "windows下vim的lua支持问题?" 一文汇总的解决方案. 题主提供了不错的 ...