温馨提示×

JavaScript返回上一页的方法有哪些

小亿
86
2024-02-27 17:47:15
栏目: 编程语言

JavaScript返回上一页的方法有以下几种:

  1. 使用浏览器的history对象的go()方法,参数为-1,表示返回上一页:
window.history.go(-1);
  1. 使用浏览器的history对象的back()方法,也可以返回上一页:
window.history.back();
  1. 使用浏览器的location对象的href属性,设置为document.referrer,表示返回上一页的URL:
window.location.href = document.referrer;

这些方法都可以用来返回到上一页,具体使用哪种方法取决于具体的需求和场景。

0