PHP前端开发

js跳转页面怎么设置

百变鹏仔 3天前 #JavaScript
文章标签 跳转
如何设置 javascript 页面跳转?使用 window.location 对象:设置 href、assign 或 replace 属性来直接跳转、无历史记录跳转或替换当前页面。使用 document.location 对象:与 window.location 类似,但适用于框架或 iframe 页面。使用 window.open 方法:在新窗口或标签页中打开 url。使用 location.reload() 方法:重新加载当前页面,忽略缓存数据。使用 history.back()/hist

如何设置 JavaScript 页面跳转

1. window.location

window.location 对象提供了一系列属性和方法来控制页面跳转。

2. document.location

document.location 对象与 window.location 类似,但它适用于基于框架或 iframe 的页面。

3. window.open

window.open("new_url"); 方法在一个新窗口或标签页中打开指定的 URL。

4. location.reload()

location.reload(); 方法重新加载当前页面,忽略任何缓存数据。

5. history.back()/history.forward()

history.back(); 和 history.forward(); 方法可让用户在浏览器的历史记录中向前或向后导航。

实例:

// 将页面跳转到 "https://example.com"window.location.href = "https://example.com";// 在新窗口中打开 "https://example.com"window.open("https://example.com");// 重新加载当前页面location.reload();// 在浏览器历史记录中后退一步history.back();