honkit / honkit

:book: HonKit is building beautiful books using Markdown - Fork of GitBook

Home Page:https://honkit.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Browser button "Return to previous page" incorrect scrolling behaviour

nomisbo opened this issue · comments

Summary

When using links to other references within one book the "Return to previous page" button of browsers does not lead back to the previous postition in the document. Instead the scroll position is determined by the URL. This deviates from expected standard behaviour of websites.

  • HonKit version: 4.0.7

Step to reproduce

  1. Go to https://honkit.netlify.app/pages.html
  2. Scroll to Button
  3. click on "templating" link
  4. click Back Button of browser

Expected results

Page shows previous scroll position (Button of Page)

Actual results

Page is not scrolled to button but shows to the beginning of the page

commented

HonKit default theme use pjax-like navigation.

Probably, we need to store scroll position before going to next page.

  1. store scroll position for the page to sessionStorage
  2. navigation
  3. back navigation to the page
  4. restore scroll position from sessionStorage if scroll position is saved

Curretly, It looks like scroll to .book-summary when changing page.

// Merge body
var bodyClass = $(".book").attr("class");
var scrollPosition = $(".book-summary").scrollTop();
$pageBody.toggleClass("with-summary", $(".book").hasClass("with-summary"));
$(".book").replaceWith($pageBody);
$(".book").attr("class", bodyClass);
$(".book-summary").scrollTop(scrollPosition);
// Update state
gitbook.state.$book = $(".book");
preparePage(!hash);
// Scroll to hashtag position
if (hash) {
scrollToHash(hash);
}

📝 New Navigation API relates with this issue, but it is in only Chrome.