fix(#471): replace legacy print.html button to prevent repeated print trigger#472
fix(#471): replace legacy print.html button to prevent repeated print trigger#472melvnl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Your proposal doesn't seem to work properly. It causes only the current page to be printed, whereas the current implementation prints the entire book.
Printing the current page only can already be easily achieved with the browser (e.g. pressing Ctrl+p), but printing the entire book is only possible with this button.
In your issue you said this:
The current Print button links to print.html (which doesn't exists)
That is incorrect, it does exist. After building the book you'll find a book/ folder in the root, next to book.toml. The link to the entire book (which is being printed when the user clicks on that button), is book/html/print.html.
Edit: Also, please write "Fix #471" in your PRs description, so that github properly links this PR to that issue and auto closes #471 once this PR gets merged.
|
You’re absolutely right, sorry about that. After looking into it more closely, I realize my current proposal indeed only prints the current page, which doesn’t match the existing behavior. As you pointed out, printing a single page can already be done easily via the browser (e.g. Ctrl + P), while the value of this button is specifically printing the entire book. I do have a small idea / gist on how we could tackle printing the whole book (not just the current page) while also fixing the re-triggered print function. I’ll take some time to refine this approach and update the PR accordingly. Thanks again for the detailed explanation. |
e459e43 to
d31236c
Compare
|
Hi, I've just updated the PR with new fix. This fix addresses the issue where navigating back or forward to the print.html page causes the print dialog to re-trigger indefinitely. The current JavaScript-based solution uses a URL parameter to verify intent and history.replaceState to clean the history stack. While this avoids re-triggering, it can occasionally result in duplicate history entries (e.g., needing to click 'back' twice). If a cleaner user experience is preferred, this can be resolved more robustly by overriding the index.hbs template to manage the print trigger via sessionStorage without affecting the URL or history flow EDIT: I can also open a separate PR to demonstrate how the changes would look by modifying index.hbs to remove the automatic print behavior in print.html |
Summary
This PR fixes the legacy print button behavior that causes the browser print dialog to be re-triggered unintentionally when navigating back or forward after canceling printing. See the issue #471
The current implementation links to
/print.html, which leads to poor print usage and UX on both desktop and mobile.Problem
/print.htmlThis is a UI glitch that breaks expected print usage and disrupts normal reading flow.
Solution
/print.htmlwindow.print()directly via JavaScriptThis ensures:
Implementation
js/print.jswith a click handler for the print buttonadditional-jsinbook.tomlRelated Issue
#471