location.href(window.location.href用法总结)

发布时间:2025-12-11 01:06:47 浏览次数:1

window.location.href用于获取或者设置当前页面的URL地址。

获取当前页面的URL地址:var url = window.location.href;

设置当前页面的URL地址:window.location.href = “https://www.example.com”;

重定向到另一个页面:window.location.href = “https://www.example.com/page2”;

在当前页面打开一个新的URL:window.open(“https://www.example.com”);

刷新当前页面:window.location.href = window.location.href;

获取URL中的查询参数:var queryString = window.location.search;

判断当前页面是否是https协议:var isHttps = (window.location.protocol === “https:”);

总结:window.location.href是一个非常常用的用于控制和获取URL地址的属性,可以用于跳转页面、刷新页面、获取URL中的查询参数等操作。

location.href
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477