From ab9a27f6fd317c083c64f4355719c12ce7a4af48 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 26 Aug 2024 21:38:47 +0530 Subject: [PATCH] Better fix for anchors that dont yield elements --- src/pyj/read_book/anchor_visibility.pyj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/anchor_visibility.pyj b/src/pyj/read_book/anchor_visibility.pyj index f97cf501ea..e5bbb24eb4 100644 --- a/src/pyj/read_book/anchor_visibility.pyj +++ b/src/pyj/read_book/anchor_visibility.pyj @@ -36,7 +36,14 @@ def position_for_anchor(anchor, is_page_list_anchor): if val?: return val anchor_funcs = get_boss().anchor_funcs - elem = document.getElementById(anchor) + if anchor: + elem = document.getElementById(anchor) + if not elem: + q = document.getElementsByName(anchor) + if q and q.length: + elem = q[0] + else: + elem = document.body if is_page_list_anchor: ensure_page_list_target_is_displayed(elem) val = anchor_funcs.pos_for_elem(elem) if elem else anchor_funcs.pos_for_elem()