Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser button "Return to previous page" incorrect scrolling behaviour #339

Open
nomisbo opened this issue Apr 24, 2023 · 1 comment
Open
Labels
Type: Theme Theme related

Comments

@nomisbo
Copy link

nomisbo commented Apr 24, 2023

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

@azu azu added the Type: Theme Theme related label Apr 24, 2023
@azu
Copy link
Member

azu commented Apr 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Theme Theme related
Projects
None yet
Development

No branches or pull requests

2 participants