Skip to content

Commit e13cb76

Browse files
committed
8249133: Javadoc: Browser back navigation does not jump to previous position anymore
Reviewed-by: jjg
1 parent 955aee3 commit e13cb76

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,26 @@ function indexFilesLoaded() {
101101
&& memberSearchIndex
102102
&& tagSearchIndex;
103103
}
104+
105+
// Workaround for scroll position not being included in browser history (8249133)
106+
document.addEventListener("DOMContentLoaded", function() {
107+
var contentDiv = document.querySelector("div.flex-content");
108+
window.onpopstate = function(e) {
109+
if (e.state !== null) {
110+
contentDiv.scrollTop = e.state;
111+
}
112+
}
113+
window.onhashchange = function(e) {
114+
history.replaceState(contentDiv.scrollTop, document.title);
115+
}
116+
contentDiv.onscroll = function(e) {
117+
var timeoutID;
118+
if (!timeoutID) {
119+
timeoutID = setTimeout(function() {
120+
history.replaceState(contentDiv.scrollTop, document.title);
121+
timeoutID = null;
122+
}, 100);
123+
}
124+
}
125+
history.replaceState(contentDiv.scrollTop, document.title);
126+
});

0 commit comments

Comments
 (0)