Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/gtk/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,11 +1320,34 @@ HtmlOutput(char *text, GtkWidget *gtkText, MOD_FONT *mf, char *anchor)
for (q = safe_anchor; (q = strstr(q, "</")) != NULL; q += 2)
q[1] = '\\';
g_free(esc_anchor);
buf =
g_strdup_printf("<script type=\"text/javascript\" language=\"javascript\">"
" window.onload = function () { window.location.hash = \"%s\"; }"
" </script>",
safe_anchor);
#ifdef WIN32
// old windows webkit1 requires different attempt at scroll-to-anchor.
buf = g_strdup_printf("<script type=\"text/javascript\">"
"window.onload = function() {"
" setTimeout(function() {"
" var name = '%s';"
" var el = document.getElementsByName(name)[0] || document.getElementById(name);"
" if (el) {"
" var y = 0;"
" var node = el;"
" while (node) {"
" y += node.offsetTop;"
" node = node.offsetParent;"
" }"
" window.scrollTo(0, y);"
" document.documentElement.scrollTop = y;"
" document.body.scrollTop = y;"
" }"
" }, 10);"
"};"
"</script>", safe_anchor);
#else
// the older location.hash method still works most reliably in modern webkit2.
buf = g_strdup_printf("<script type=\"text/javascript\" language=\"javascript\">"
" window.onload = function () { window.location.hash = \"%s\"; }"
" </script>",
safe_anchor);
#endif
g_free(safe_anchor);
XIPHOS_HTML_WRITE(html, buf, strlen(buf));
g_free(buf);
Expand Down