在不使用历史 API 重新加载的情况下进入以前的状态?

Go to previous state without reload with history API?

提问人:cak3_lover 提问时间:7/16/2023 更新时间:7/16/2023 访问量:23

问:

我有一张图片,点击时会全屏显示,按下浏览器后退按钮会将其最小化

enter image description here

或连接到的任何其他也将其最小化<button>fullscreen()

到目前为止,我想出了这个:

function fullscreen(show){
  if(show){
    ... # maximize image
    history.pushState({id:1},null)
  }
  else{
    ... # minimize image
    history.go(0)
  }
  
window.addEventListener("popstate",()=>{
  fullscreen(false)
});

小提琴(但您必须在本地文件上运行它).html

但问题是这种方法会重新加载整个页面 那么有没有办法防止页面重新加载呢?

javascript html 浏览器历史 .js

评论


答: 暂无答案