// 获取当前页面的完整 URL
var currentUrl = window.location.href;
console.log("当前页面的完整 URL 是: " + currentUrl);
// 获取协议 (http, https)
var protocol = window.location.protocol;
console.log("协议是: " + protocol);
// 获取主机名 (域名)
var hostname = window.location.hostname;
console.log("主机名是: " + hostname);
// 获取端口号
var port = window.location.port;
console.log("端口号是: " + port);
// 获取路径
var pathname = window.location.pathname;
console.log("路径是: " + pathname);
// 获取查询参数
var search = window.location.search;
console.log("查询参数是: " + search);
// 获取 hash 值
var hash = window.location.hash;
console.log("hash 值是: " + hash);
window.location.href:获取当前页面的完整 URL。window.location.protocol:获取 URL 的协议部分(例如 http: 或 https:)。window.location.hostname:获取 URL 的主机名(域名部分)。window.location.port:获取 URL 的端口号(如果有的话)。window.location.pathname:获取 URL 的路径部分。window.location.search:获取 URL 中的查询参数部分(从 ? 开始的部分)。window.location.hash:获取 URL 中的 hash 部分(从 # 开始的部分)。上一篇:js 刷新页面
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站