location.href是JavaScript中用來獲取或設置當前頁面URL的屬性。它可以有以下幾種用法:
var currentURL = location.href;
location.href = "https://www.example.com";
var url = location.href;
url += (url.indexOf('?') === -1 ? '?' : '&') + 'param=value';
location.href = url;
location.href = "https://www.example.com";
location.href = location.href;
總之,location.href屬性提供了訪問和修改當前頁面URL的便捷方式。