zoukankan      html  css  js  c++  java
  • HTML URL地址解析

    通过JavaScript的location对象,可获取URL中的协议、主机名、端口、锚点、查询参数等信息。

    示例

    URLhttp://www.akmsg.com/WebDemo/URLParsing.html#top?username=admin&pwd=123456

    解析结果: 

    属性名称获取的值说明
    location.hash #top?username=admin&pwd=123456 URL中的的锚点部分,包含开头的#符号
    location.host www.akmsg.com 主机名称和端口
    location.hostname www.akmsg.com 主机名称
    location.href http://www.akmsg.com/WebDemo/URLParsing.html#top?username=admin&pwd=123456 完整的URL
    location.pathname /WebDemo/URLParsing.html 路径部分
    location.port   端口
    location.protocol http: 协议,最后面会有个':'冒号
    location.search   URL的查询部分(从问号 (?) 开始的 URL)
    注意:当URL含有锚点时,此处返回空字符。
    location.origin http://www.akmsg.com URL的源。返回格式:协议+主机名+端口
    location.origin+location.pathname http://www.akmsg.com/WebDemo/URLParsing.html URL的访问地址。返回格式:协议+主机名+端口+路径部分

    代码

    console.log(
    	'location.hash     :' + location.hash     + '
    ' +
    	'location.host     :' + location.host     + '
    ' +
    	'location.hostname :' + location.hostname + '
    ' +
    	'location.href     :' + location.href     + '
    ' +
    	'location.pathname :' + location.pathname + '
    ' +
    	'location.port     :' + location.port     + '
    ' +
    	'location.protocol :' + location.protocol + '
    ' +
    	'location.hash     :' + location.hash     + '
    ' +
    	'location.search   :' + location.search   + '
    ' +
    	'location.origin   :' + location.origin 
    )
    

    在线示例

    地址http://www.akmsg.com/WebDemo/URLParsing.html

  • 相关阅读:
    python3--生成器
    python3--列表生成式
    python3--装饰器高级学习版
    python3--嵌套函数
    python3-装饰器
    《Hexo+github搭建个人博客》
    Html网页的代码
    关于内联框架
    性能调优
    Java知识总结
  • 原文地址:https://www.cnblogs.com/polk6/p/6024886.html
Copyright © 2011-2022 走看看