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

  • 相关阅读:
    Ubuntu通过ADB连接手机
    MyRolan (快速启动小工具)
    关闭QQ右下角弹窗小程序
    day23作业-韩明琰
    day18-20作业-韩明琰
    day14-16作业-韩明琰
    java中对于多态的理解
    day11作业-韩明琰
    day10作业-韩明琰
    day09_作业
  • 原文地址:https://www.cnblogs.com/polk6/p/6024886.html
Copyright © 2011-2022 走看看