Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js 获取地址

作者:爱我者我必爱*   发布日期:2026-07-22   浏览:99

// 获取当前页面的完整 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 刷新页面

下一篇:js decodeuricomponent

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js fill方法

js 数组连接

js json数组

js 数组复制

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站