// 获取浏览器地址的示例代码
// 使用 window.location.href 获取当前页面的完整 URL
var currentUrl = window.location.href;
console.log("当前页面的完整 URL 是: " + currentUrl);
// 如果只需要获取协议、主机名、端口等特定部分,可以使用以下属性
var protocol = window.location.protocol; // 获取协议(例如:http: 或 https:)
var hostname = window.location.hostname; // 获取主机名(例如:www.example.com)
var port = window.location.port; // 获取端口号(如果有的话)
var pathname = window.location.pathname; // 获取路径部分(例如:/path/to/page)
var search = window.location.search; // 获取查询字符串(例如:?key=value)
var hash = window.location.hash; // 获取哈希部分(例如:#section)
console.log("协议: " + protocol);
console.log("主机名: " + hostname);
console.log("端口: " + port);
console.log("路径: " + pathname);
console.log("查询字符串: " + search);
console.log("哈希: " + hash);
上一篇:js 鼠标右键
下一篇:js 播放器
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站