0

I am implementing swipe function inside article page. For example: If you are reading article from category CSS, when you swipe left (inside post-content div) you will get next article from category CSS. When you swiperight you are suposed to go on previous article (this works exactly as expected). But when I press back button (on mobile browser) I am not returned to previous article I am either returned to my last typed link (for example if I entered, manually, link www.example.com, I would be redirected to this link), or to some arbitrary link while I was swiping through.

This code is used for swiping through articles, forward.

$("body").on("swipeleft", "#post-content", function(event) {
    $("#post-page").addClass("fade-out");
    event.preventDefault();

    if (!$(event.target).closest('.gallery').length) {
        var url = window.location.href;
        var arr = url.split("/");
        var domain = arr[0] + "//" + arr[2];
        window.location.href= domain + "/mobile-vijest/" + NEXTTEXTURL + "/" + NEXTTEXTID;
  }
});

This code is being used for going back through history (IT' S WORKING GREAT):

$("body").on("swiperight", "#post-content", function(event) {
    event.preventDefault();

    history.back();
});

So, how do I make my back button to work as I expected it to?

Korovjov
  • 503
  • 5
  • 17
  • 1
    does this help? https://stackoverflow.com/a/18213393/4845566 – deblocker Jan 25 '20 at 17:34
  • 1
    Because you have to use jQM built-in page change method (Ajax system) instead of `window.location`. The former adds an entry to browsing history, which you need to navigate backward and forward. – Omar Jan 27 '20 at 08:31

0 Answers0