• JavaScript window.location对象


    经常使用window.location,它的结构总是记不住,简单梳理下,方便以后查询。

    示例

    URL:http://b.a.com:88/index.php?name=kang&when=2011#first

    属性含义
    protocol: 协议 "http:"
    hostname: 服务器的名字 "b.a.com"
    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'
    这种方式会讲新地址放到浏览器历史栈中,意味着转到新页面后“后退按钮”仍可以回到该页面。
    location.replace( url )
    与assign方法一样,但会从浏览器历史栈中删除本页面,也就是说跳转到新页面后“后退按钮”不能回到该页面。目前IE、Chrome只是简单的跳转,只有Firefox会删除本页面的历史记录。
    location.reload( force )
    重新载入当前页面。force为true时从服务器端重载;false则从浏览器缓存中重载,默认值false。
  • 相关阅读:
    元数据 缓存 池 模式
    ContractPattern 面向面向契约模式
    第三方登录 ----转载自简书,作者 <<碧霄问鼎>>
    证书那些事
    导航(NavanavigationController)push和pop
    iOS app上传错误集锦(转载)
    Block 的基本用法
    正则表达式的用法 转载
    UIView
    UIDate(时间)
  • 原文地址:https://www.cnblogs.com/rainman/p/1959054.html
Copyright © 2020-2023  润新知