js window.location用法
<script>
//设置或获取 href 属性中跟在问号后面的部分。
console.log(window.location.search)
//设置或获取对象指定的文件名或路径
console.log(window.location.pathname)
//设置或获取整个 URL 为字符串。
console.log(window.location.href);
//设置或获取与 URL 关联的端口号码。
console.log(window.location.port)
//设置或获取 URL 的协议部分。
console.log(window.location.protocol)
///设置或获取 href 属性中在井号“#”后面的分段。
console.log(window.location.hash)
//设置或获取 location 或 URL 的 hostname 和 port 号码。
console.log(window.location.host)
</script>
window.location用法
2011 年 09 月 28 日 window.location.href=“url”:改变url地址;
window.location.replace(“url”):将地址替换成新url,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后 退”来访问已经被替换的URL,这个特点对于做一些过渡页面非常有用!
window.location.reload():强制刷新页面,从服务器重新请求!
window.location.href和window.location.replace的区别:
假设有3个jsp页面(1.jsp, 2.jsp, 3.jsp),进系统默认的是1.jsp ,当我进入2.jsp的时候, 2.jsp里面用window.location.replace(“3.jsp”);与用window.location.href(“3.jsp”);从用户界面来看是没有什么区别的,但是当3.jsp页面有一个“返回”按钮,调用window.history.go(-1);wondow.history.back();方法的时候,一点这个返回按钮就要返回2.jsp页面的话,区别就出来了,当用window.location.replace(“3.jsp”);连到3.jsp页面的话,3.jsp页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到1.jsp 。当用window.location.href(“3.jsp”);连到3.jsp页面的话,3.jsp页面中的调用window.history.go(-1);wondow.history.back();方法是好用的,会返回2.jsp。因为window.location.replace(“3.jsp”);是不向服务器发送请求的跳转,而window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以会跳到系统默认页面1.jsp 。window.location.href(“3.jsp”);是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以就可以返回到2.jsp。
…………………………………………………………………………
window.location和window.open区别:
在给按钮、表格、单元格、下拉列表和DIV等做链接时一般都要用Javascript来完成,和做普通链接一样,可能需要让链接页面在当前窗口打开,也可能需要在新窗口打开,这时就可以使用下面两项之一来完成:
window.open 用来打开新窗口
window.location 用来替换当前页,也就是重新定位当前页
可以用以下来个实例来测试一下。
<input type=”button” value=”新窗口打开” onclick=”window.open(‘http://www.zhousl.com/’)”>
<input type=”button” value=”当前页打开” onclick=”window.location=’http://www.zhousl.com/’”>
…………………………………………………………………………
window.location.Reload()和window.location.href=window.location.href;都是刷新当前页面。
window.location.Reload()如果有数据提交的话,会提示是否提交的(是和否选项)
window.location.href=window.location.href是定向url提交数据
最好不要用location.reload(),而用location=location比较好,还有在模式窗口(showModalDialog和showModelessDialog)前者不能用。
reload() 方法用于重新加载当前文档。
语法
location.reload(force)说明
如果该方法没有规定参数,或者参数是 false,它就会用 HTTP 头 If-Modified-Since 来检测服务器上的文档是否已改变。如果文档已改变,reload() 会再次下载该文档。如果文档未改变,则该方法将从缓存中装载文档。这与用户单击浏览器的刷新按钮的效果是完全一样的。
如果把该方法的参数设置为 true,那么无论文档的最后修改日期是什么,它都会绕过缓存,从服务器上重新下载该文档。这与用户在单击浏览器的刷新按钮时按住 Shift 健的效果是完全一样。
转自:http://www.cnblogs.com/andy-wcl/p/3444146.html
js window.location用法的更多相关文章
- Arison [JS]window.location获取url各项参数详解
https://www.cnblogs.com/Arison/p/5286368.html 对于这样一个URL代码如下 复制代码 http://www.php230.com :80/fisker/po ...
- [JS]window.location获取url各项参数详解
window.location方法后还还可以带href,search等参数,下面我们来看看获取url各项参数的办法. URL即:统一资源定位符 (Uniform Resource Locator, U ...
- js href的用法
关于js window.location.href location.href parent.location.href top.location.href 的用法 "window.loca ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
location.href 和 window.location.href 区别: 1.location.href 可以直接跳转其他地址(不属于本项目) 也可以跳转本项目中的 2.window.loca ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别(跳出iframe方法)
"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"是上一 ...
- js中window.location的用法
用window.location处理解析当前页面URL window.location 对象所包含的属性 属性 描述 hash 从井号(#)开始的URL(锚点) host 主机名和当前URL的端口号 ...
- js中的window.location.search的用法与作用。
用该属性获取页面 URL 地址: window.location 对象所包含的属性 属性 描述 hash 从井号 (#) 开始的 URL(锚) host 主机名和当前 URL 的端口号 hostnam ...
随机推荐
- 本地项目初始化git推送到服务器
1. 创建本地项目,在项目根目录执行git init命令 git init 2.在git服务器上创建一个仓库,这里使用GitHub创建一个仓库. 3.执行git remote add origin & ...
- fcgi-2.4.1 fastcgi开发包 make编译出错
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':fcgio.cpp:50: error: 'EOF' was ...
- 加密、签名和SSL握手机制细节
openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 1.1 背景知识 对称加密 :加密解密使用同一密钥,加解密速度快.随 ...
- hadoop之安装
在Linux环境下安装Hadoop: 一.安装环境 硬件:虚拟机 操作系统:Centos 6.4 64位 IP:192.168.153.130主机名:imooc安装用户:root ...
- python -- 约束、异常处理、MD5
1.类的约束 1.写一个父类,父类中的某个方法要抛出一个异常 NotImplementedError class Base: # 对子类进行了约束,必须重写该方法 def login(se ...
- SpringCloud调用服务原理
- CopyOnWriteArrayList&Collections.synchronizedList()
1.ArrayList ArrayList是非线性安全,此类的 iterator() 和 listIterator() 方法返回的迭代器是快速失败的:在创建迭代器之后,除非通过迭代器自身的 remov ...
- 数据的双向绑定 Angular JS之开端篇
接触AngularJS许了,时常问自己一些问题,如果是我实现它,会在哪些方面选择跟它相同的道路,哪些方面不同.为此,记录了一些思考,给自己回顾,也供他人参考. 初步大致有以下几个方面: 数据双向绑定 ...
- 【问题】用ant编译时,提示编码utf为不可映射字符
分析:eclipse默认的编码为gbk,而ant里的build.xml文件里定义的为utf-8格式.两者格式不统一. 建议:将工程的编码改成utf-8的格式,一般java工程也建议为utf-8格式.
- h5手机点击返回键,刷新页面
在js中,加上一下代码: window.onpageshow = function(event) {if (event.persisted) {window.location.reload();}};