zoukankan      html  css  js  c++  java
  • window.location属性

    编写一个javascript的函数把url解析为与页面的javascript.location对象相似的实体对象,如:url :'http://www.qq.com/index.html?key1=1&key2=2',最后输出的对象是:

    {
        protocol: "http", 
        hostname: "www.qq.com", 
        pathname: "index.html", 
        query: "key1=1&key2=2"
    }
    function parseUrl ( url )
    {
           var map = {};
           var protocol = url.search(":") > 0 ? url.split(":")[0] : "";   //在url中":"前面的是协议;
           var newUrl = protocol ? url.replace( protocol + "://" , "") : url;  //将url中的协议部分去除掉
           var arr = newUrl.split("/");
           hostname = arr[0];
           pathname = arr[1] ? arr[1].split("?")[0] : "";
           query = arr[1] ? arr[1].split("?")[1] : "";
           map = {
    protocol : protocol , hostname : hostname, pathname : pathname, query : query }
    return map; }

      

      

    window.location 对象所包含的属性

    属性描述
    hash 从井号 (#) 开始的 URL(锚)
    host 主机名和当前 URL 的端口号
    hostname 当前 URL 的主机名
    href 完整的 URL
    pathname 当前 URL 的路径部分
    port 当前 URL 的端口号
    protocol 当前 URL 的协议
    search 从问号 (?) 开始的 URL(查询部分)

  • 相关阅读:
    Matplotlib.pyplot 三维绘图
    Matplotlib.pyplot 二维绘图
    面对对象进阶
    面对对象基础
    python安装第三方模块
    json & pickle
    os模块
    sys模块
    正则表达式
    Python2与Python3的编码差异
  • 原文地址:https://www.cnblogs.com/shixiaomiao/p/4780674.html
Copyright © 2011-2022 走看看