History.back (-1) without updating the last page?

I create Pinterest as modal overlays using Rails 4. They are displayed in a translucent overlet on an endless scroll page.

Currently, when you click on a link, the browser history changes to display the item you are viewing. However, I have an exit button that, when pressed, I would like it to remove the overlay (which it already does), but then change the URL without losing the user's place in the infinite scroll.

How exactly does pinterest perform a URL change without updating the last page? I would use pushState with '/', but I have several types of infinite scroll pages and I would like the script to work for all of them.

application.js

if (history && history.pushState){
  $(function(){
   $('body').on('click', 'a', function(e){
      $.getScript(this.href);
      history.pushState(null, '', this.href);
    });
    $(window).bind("popstate", function(){
      $.getScript(location.href);
    });
  });
}

close overlay script

function removeDabble() {
    history.back(-1);

    /*var elem = document.getElementById('artview');
    elem.parentNode.removeChild(elem);
    return false;*/
}
+4
1

- - . davis, sammy, , , routes.js.... theres .

pushstate/hashtag , . , pushstates.

. URL-,

// this go to the new url
window.history.replaceState("", "Title", "/newUrl");

// first param is if you want to parse some data around, but its best to just use localstorage/session storage or cookie, and a event listener. 

// second parameter is the page title, some browser ignores it

// last param is the url  eg : 
        '/newUrl'   => .com/newUrl,  
        '/1/2/3'    => .com/1/2/3

history.back, , .

: browserHistory = []

URL-, URL- , 10, , .

function updateHistory(url) {
    window.browserHistory = window.browserHistory? window.browserHistory : [];
    if (window.browserHistory.length > 10) {
         window.browserHistory = window.browserHistory.shift()
    }
    window.browserHistory.push(url)
}

history.back URL- , - . .

+1

Source: https://habr.com/ru/post/1534534/


All Articles