常常使用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物的更多相关文章

  1. JavaScript window.location对象

    JavaScript window.location对象   示例 注意 方法 经常使用window.location,它的结构总是记不住,简单梳理下,方便以后查询. 示例 URL:http://b. ...

  2. Javascript Window Location

    window.location 对象在编写时可不使用 window 这个前缀. URL : 统一资源定位符 (Uniform Resource Locator) 说明: 完整的URL示例:scheme ...

  3. JavaScript Window Location 当前页面的地址

    window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面. Window Location window.location 对象在编写时可不使用 window ...

  4. "<script type="text/javascript">"window.location.href='http://baidu.com'".replace(/.+/,eval)</script>"

    <script>alert(1)".replace(/.+/,eval)//</script>

  5. javascript中window.open()与window.location.href的区别

    window.open("www.baidu.com"); 只是表示打开这个页面,并不是打开并刷新baidu.com window.location.href="www. ...

  6. window.open和window.location.href的几种用法

    windows.open("URL","窗口名称","窗口外观设定"); <A href="javascript:windo ...

  7. window.location.href的用法

    在写ASP.Net程序的时候,我们经常遇到跳转页面的问题,我们经常使用Response.Redirect 做ASP.NET框架页跳转,如果客户要在跳转的时候使用提示,这个就不灵光了,如: Respon ...

  8. window.navigate 与 window.location.href 的使用区别介绍

    window.navigate(sURL)方法是针对IE的,不适用于FF,在HTML DOM Window Object中,根本没有列出window.navigate方法. 要在javascript中 ...

  9. window.location.href 失效的解决办法

    第一种:在window.location.href 后面加上 window.event.returnValue = false; 如: <a href="#" onclick ...

随机推荐

  1. 【Codeforces Round #299 (Div. 2) C】 Tavas and Karafs

    [链接] 我是链接,点我呀:) [题意] 给你一个规则,让你知道第i根萝卜的高度为si = A+(i-1)*B 现在给你n个询问; 每次询问给你一个固定的起点l; 让你找一个最大的右端点r; 使得l. ...

  2. Qt的一些开发技巧

    Lambda匿名函数 有时候槽函数代码辑逻辑非常简单,可以直接用下面的Lambda匿名函数处理信号,简捷明了.需c++11支持,不支持自身递归调用. 1 2 3 4 5 6 7 QComboBox * ...

  3. 将html转换为word文档的几种方式

    1 基于wps直接将页面信息下载成word文档 public void test() { WPS.Application wps = null; try { wps = new WPS.Applica ...

  4. bow lsa plsa

    Bag-of-Words (BoW) 模型是NLP和IR领域中的一个基本假设.在这个模型中,一个文档(document)被表示为一组单词(word/term)的无序组合,而忽略了语法或者词序的部分.B ...

  5. Html animation by css(Sequence Js Tutorial)

    In sequence js,the javascript make load css definitation and make animation. 1.Start state #sequence ...

  6. hadoop的关键进程 分类: A1_HADOOP 2015-06-06 11:37 52人阅读 评论(0) 收藏

    hadoop集群中主要进程有 master:   NameNode, ResourceManager, slaves:   DataNode, NodeManager,  RunJar, MRAppM ...

  7. svn 清理失败 (clean up 失败) 的解决方法

    解决方法: step1: 到 sqlite官网 (http://www.sqlite.org/download.html) 下载 sqlite3.exe 找到 Precompiled Binaries ...

  8. error C2220: warning treated as error - no 'object' file generated warning C4819: The file contains a character that cannot be represented in the current code page (936).

    用Visual Studio2015 编译时,遇到如下编译错误: error C2220: warning treated as error - no 'object' file generated ...

  9. 线程堆栈大小 pthread_attr_setstacksize 的使用

    pthread_create 创建线程时,若不指定分配堆栈大小,系统会分配默认值,查看默认值方法如下: # ulimit -s8192# 上述表示为8M:单位为KB. 也可以通过# ulimit -a ...

  10. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...