JavaScript window.location物
常常使用window.location。它的结构总是记不住。简单梳理下。方便以后查询。
演示样例
URL:http://b.a.com:88/index.php?
name=kang&when=2011#first
| 属性 | 含义 | 值 |
|---|---|---|
| protocol: | 协议 | "http:" |
| hostname: | server的名字 | "b.a.com" |
| port: | port | "88" |
| pathname: | URL中主机名后的部分 | "/index.php" |
| search: |
"?
"后的部分,又称为查询字符串 |
"?name=kang&when=2011" |
| hash: | 返回"#"之后的内容 | "#first" |
| host: | 等于hostname + port | "b.a.com:88" |
| href: | 当前页面的完整URL | "http://www.a.com:88/index.php?name=kang&when=2011#first" |
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" | 第一个"#"之后的内容 |
方法
- location.assign( url )
- location.assign('http://www.baidu.com'); 等同于 window.location = 'http://www.baidu.com'
这样的方式会讲新地址放到浏览器历史栈中,意味着转到新页面后“后退button”仍能够回到该页面。 - location.replace( url )
- 与assign方法一样,但会从浏览器历史栈中删除本页面,也就是说跳转到新页面后“后退button”不能回到该页面。眼下IE、Chrome仅仅是简单的跳转,仅仅有Firefox会删除本页面的历史记录。
- location.reload( force )
- 又一次加载当前页面。force为true时从server端重载;false则从浏览器缓存中重载,默认值false。
版权声明:本文博主原创文章,博客,未经同意不得转载。
JavaScript window.location物的更多相关文章
- JavaScript window.location对象
JavaScript window.location对象 示例 注意 方法 经常使用window.location,它的结构总是记不住,简单梳理下,方便以后查询. 示例 URL:http://b. ...
- Javascript Window Location
window.location 对象在编写时可不使用 window 这个前缀. URL : 统一资源定位符 (Uniform Resource Locator) 说明: 完整的URL示例:scheme ...
- JavaScript Window Location 当前页面的地址
window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面. Window Location window.location 对象在编写时可不使用 window ...
- "<script type="text/javascript">"window.location.href='http://baidu.com'".replace(/.+/,eval)</script>"
<script>alert(1)".replace(/.+/,eval)//</script>
- javascript中window.open()与window.location.href的区别
window.open("www.baidu.com"); 只是表示打开这个页面,并不是打开并刷新baidu.com window.location.href="www. ...
- window.open和window.location.href的几种用法
windows.open("URL","窗口名称","窗口外观设定"); <A href="javascript:windo ...
- window.location.href的用法
在写ASP.Net程序的时候,我们经常遇到跳转页面的问题,我们经常使用Response.Redirect 做ASP.NET框架页跳转,如果客户要在跳转的时候使用提示,这个就不灵光了,如: Respon ...
- window.navigate 与 window.location.href 的使用区别介绍
window.navigate(sURL)方法是针对IE的,不适用于FF,在HTML DOM Window Object中,根本没有列出window.navigate方法. 要在javascript中 ...
- window.location.href 失效的解决办法
第一种:在window.location.href 后面加上 window.event.returnValue = false; 如: <a href="#" onclick ...
随机推荐
- 洛谷——P1774 最接近神的人_NOI导刊2010提高(02)
https://www.luogu.org/problem/show?pid=1774 题目描述 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古 ...
- Codeforces Round #Pi (Div. 2) B Berland National Library
B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...
- [Err] 1136 - Column count doesn't match value count at row 1
1 错误描写叙述 [Err] 1136 - Column count doesn't match value count at row 1 Procedure execution failed 113 ...
- 一、Github博客搭建之jekyll安装
注意:以下步骤是FQ后操作的,需要了解FQ的可以移步 -> 枫叶主机 一.安装jekyll需要Ruby-2.1.0以上版本,本人是mac pro系统版本10.12.5(macOS Sierra) ...
- hdu 3306 Another kind of Fibonacci(矩阵高速幂)
Another kind of Fibonacci Time Limit: 3000/10 ...
- View的事件分发机制解析
引言 Android事件构成 在Android中,事件主要包含点按.长按.拖拽.滑动等,点按又包含单击和双击,另外还包含单指操作和多指操作.全部这些都构成了Android中的事件响应.总的来说.全部的 ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- ios开发网络学习四:NSURLConnection大文件断点下载
#import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...
- Python 标准库 —— glob
glob库是最简单的模块之一,内容非常少.用它可以查找符合特定规则的文件路径名.跟使用 windows 下的文件搜索差不多.查找文件只用到三个匹配符: "*", 匹配 0 个或多个 ...
- FAST特征点检测&&KeyPoint类
FAST特征点检测算法由E.Rosten和T.Drummond在2006年在其论文"Machine Learning for High-speed Corner Detection" ...