JavaScript之History&Location对象

发布时间 2023-09-13 09:45:15作者: hasome

history对象

  • history对象是 JavaScript 对历史记录进行封装的对象。
  • history对象的获取: 使用 window.history获取,其中window. 可以省略
  • history.back(): 加载history的前一个url
  • history.forward(): 加载history的下一个url

location对象

  • Location 对象是 JavaScript 对地址栏封装的对象。可以通过操作该对象,跳转到任意页面。
  • 获取Location对象:使用 window.location获取,其中window. 可以省略
  • location.href: 跳转到某个页面
setTimeout(function (){
    location.href = "https://www.baidu.com"
},3000);

参考: https://lushimeng.blog.csdn.net/article/details/125122869