Skip to content

113 fix scroll page to top - #121

Closed
dpakprajul wants to merge 2 commits into
masterfrom
113_fix_scroll_page_to_top
Closed

113 fix scroll page to top#121
dpakprajul wants to merge 2 commits into
masterfrom
113_fix_scroll_page_to_top

Conversation

@dpakprajul

Copy link
Copy Markdown
Collaborator

fix #113 seond part.
Now it scroll the page to the top, instead of middle-bottom (when user navigates from main search page where title appear to the next page clicking the title):
grafik

@github-actions

Copy link
Copy Markdown

Code Review by Gemini

Here are a few observations and suggested improvements for the changes in http/php/mod_linkedDataProxy.php:

1. Handling DOMContentLoaded if already fired

If the document is parsed or loaded asynchronously, DOMContentLoaded might already have fired by the time this inline script runs, causing the event listener callback never to execute.

2. User Experience with Browser Back/Forward Navigation

Setting history.scrollRestoration = "manual"; permanently disables automatic scroll restoration for the current history entry. When users use the browser's Back button to return to the search results page, their previous scroll position will be lost and they will be forced back to the top.


Suggested Refactoring

<<<<
		$html .= 'if ("scrollRestoration" in history) { history.scrollRestoration = "manual"; }' . $newline;
		$html .= 'window.scrollTo(0, 0);' . $newline;
		$html .= 'document.addEventListener("DOMContentLoaded", function() {' . $newline;
		$html .= '  window.scrollTo(0, 0);' . $newline;
		$html .= '  try { if (window.parent && window.parent !== window) { window.parent.scrollTo(0, 0); } } catch(e) {}' . $newline;
====
		$html .= 'if ("scrollRestoration" in history) { history.scrollRestoration = "manual"; }' . $newline;
		$html .= 'function scrollToTop() {' . $newline;
		$html .= '  window.scrollTo(0, 0);' . $newline;
		$html .= '  try { if (window.parent && window.parent !== window) { window.parent.scrollTo(0, 0); } } catch(e) {}' . $newline;
		$html .= '}' . $newline;
		$html .= 'scrollToTop();' . $newline;
		$html .= 'if (document.readyState === "loading") {' . $newline;
		$html .= '  document.addEventListener("DOMContentLoaded", scrollToTop);' . $newline;
		$html .= '}' . $newline;
>>>>

@dpakprajul

Copy link
Copy Markdown
Collaborator Author

I tried different way (as suggested by gemini-review) to make the back page lead to scroll to the same position, but it force back to the top.

/*
 * NOTE: Known Limitation - Scroll Restoration vs. Scroll-to-Top
 * 1. Forcing scroll-to-top on new page load requires history.scrollRestoration = "manual".
 * 2. Setting manual restoration breaks the browser's native Back button scroll memory.
 * 3. Because mod_linkedDataProxy.php runs inside an iframe, main scrollbar authority 
 *    belongs to the host page (geoportal.hessen.de), which resizes asynchronously.
 * Full resolution requires scroll state tracking on the host portal page level.
 */

@karlbrink karlbrink closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zoom to layer is not working while geojson is loaded in linked open data

2 participants