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?