// 获取当前页面的完整 URL
var currentUrl = window.location.href;
console.log("当前页面的完整 URL 是: " + currentUrl);
// 获取协议 (例如: http: 或 https:)
var protocol = window.location.protocol;
console.log("协议是: " + protocol);
// 获取主机名 (例如: www.example.com)
var hostname = window.location.hostname;
console.log("主机名是: " + hostname);
// 获取端口号 (例如: 80 或 443)
var port = window.location.port;
console.log("端口号是: " + port);
// 获取路径部分 (例如: /path/)
var pathname = window.location.pathname;
console.log("路径是: " + pathname);
// 获取查询字符串 (例如: ?key=value)
var search = window.location.search;
console.log("查询字符串是: " + search);
// 获取 hash 部分 (例如: #section)
var hash = window.location.hash;
console.log("hash 部分是: " + hash);
window.location.href
:返回当前页面的完整 URL。window.location.protocol
:返回当前页面的协议(如 http:
或 https:
)。window.location.hostname
:返回当前页面的主机名(如 www.example.com
)。window.location.port
:返回当前页面的端口号(如 80
或 443
)。window.location.pathname
:返回当前页面的路径部分(如 /path/
)。window.location.search
:返回当前页面的查询字符串部分(如 ?key=value
)。window.location.hash
:返回当前页面的 hash 部分(如 #section
)。上一篇:js 获取url ?后面的参数
下一篇:js 获取 url 参数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站