// 假设初始 URL 为 http://www.example.com/example/
// 将 URL 修改为"http://www.example.com/example/#section"
location.hash = “#section”;
// 将 URL 修改为"http://www.example.com/example/?id=javascript"
location.search = “?id=javascript”;
// 将 URL 修改为"http://www.yahoo.com/example/"
location.hostname = “www.yahoo.com”;
// 将 URL 修改为"http://www.yahoo.com/mydir/"
location.pathname = “mydir”;
//将 URL 修改为"http://www.yahoo.com:8080/example/"
location.port = 8080;
每次修改 location 的属性( hash 除外),页面都会以新 URL 重新加载。
修改URL
最新推荐文章于 2023-11-23 14:18:21 发布