Go to previous state without reload with history API?

50 views Asked by At

I have an image that, when clicked, goes full screen and pressing the browser back button minimizes it

enter image description here

OR any other <button> connected to the fullscreen() also minimizes it

so far I've come up with this:

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

fiddle (but you'll have to run it locally on an .html file)

but the problem is that this approach reloads the entire page so is there a way to keep the page from reloading?

0

There are 0 answers