JavaScript-js获取请求地址相关信息

  • Post author:
  • Post category:java


document对象相关参数获取 :

location:子对象

document.location.hash // #号后的部分

document.location.host // 域名+端口号

document.location.hostname // 域名

document.location.href // 完整URL

document.location.pathname // 目录部分

document.location.port // 端口号

document.location.protocol // 网络协议(http:)

document.location.search // ?号后的部分

获取#的位置截取字符串的形式 例如:

var url=window.location.href;//获取地址栏 url

var index=url.indexOf(’#’);//获取#的位置

var paramVal=url.substr(index,url.length);//获取 # 后面所有字符串



版权声明:本文为wukkk111原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。