Skip to content

Commit 0fcb7da

Browse files
Improve page hash handling
1 parent d5141e6 commit 0fcb7da

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/librustdoc/html/static/main.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ function defocusSearchBar() {
112112
}
113113

114114
function getPageId() {
115-
var id = document.location.href.split("#")[1];
116-
if (id) {
117-
return id.split("?")[0].split("&")[0];
115+
if (window.location.hash) {
116+
var tmp = window.location.hash.replace(/^#/, "");
117+
if (tmp.length > 0) {
118+
return tmp;
119+
}
118120
}
119121
return null;
120122
}
@@ -2688,8 +2690,8 @@ function defocusSearchBar() {
26882690

26892691
autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
26902692

2691-
if (window.location.hash && window.location.hash.length > 0) {
2692-
expandSection(window.location.hash.replace(/^#/, ""));
2693+
if (pageId !== null) {
2694+
expandSection(pageId);
26932695
}
26942696

26952697
if (main) {

0 commit comments

Comments
 (0)