js获取当前URL、参数、端口、IP等服务器信息



1,设置或获取对象指定的文件名或路径。
console.log(window.location.pathname)

2,设置或获取整个 URL 为字符串。
console.log(window.location.href);

3,设置或获取与 URL 关联的端口号码。

console.log(window.location.port)


4,设置或获取 URL 的协议部分。

console.log(window.location.protocol)


5,设置或获取 href 属性中在井号“#”后面的分段。

console.log(window.location.hash)

 

6,设置或获取 location 或 URL 的 hostname 和 port 号码。

console.log(window.location.host)

    1

7,设置或获取 href 属性中跟在问号后面的部分。

console.log(window.location.search)



8,获取变量的值(截取等号后面的部分)

 var url = window.location.search;

  

9,用来得到当前网页的域名

var domain = document.domain;

 

function getRootPath() {
    //获取当前网址,
    var curPath = window.document.location.href;
    //获取主机地址之后的目录,
    var pathName = window.document.location.pathname;
    var pos = curPath.indexOf(pathName);
    //获取主机地址
    var localhostPaht = curPath.substring(0, pos);
    //获取带"/"的项目名,
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    return (localhostPaht);
}

posted @   桂长江  阅读(2851)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示