Fix anchor links

This commit is contained in:
Adrian Vollmer 2022-10-10 17:41:55 +02:00
parent 351582e055
commit eb0e4110a8
2 changed files with 9 additions and 4 deletions

View File

@ -59,15 +59,14 @@ var load_virtual_page = (function (path, get_params, anchor) {
// return True if it worked
// return False if loading indicator should be removed right away
const file = window.global_context.file_tree[path];
const data = file.data;
var iframe = createIframe();
const data = file.data;
window.global_context.get_parameters = get_params;
if (file.mime_type == 'text/html') {
iframe.setAttribute("srcdoc", data);
if (anchor) {
iframe.contentDocument.location.hash = anchor;
}
window.global_context.current_path = path;
window.global_context.anchor = anchor;
window.history.pushState({path, get_params, anchor}, '', '#');
return true;
} else {

View File

@ -64,6 +64,7 @@ var virtual_click = function(evnt) {
} else {
console.error("Invalid element", el);
}
path = normalize_path(path);
window.parent.postMessage({
@ -88,6 +89,8 @@ var fix_links = function() {
var fix_link = function(a) {
if (is_virtual(a.getAttribute('href'))) {
a.addEventListener('click', virtual_click);
} else if (a.getAttribute('href').startsWith('#')) {
a.setAttribute('href', "about:srcdoc" + a.getAttribute('href'))
}
};
@ -210,6 +213,9 @@ window.addEventListener("message", (evnt) => {
argument: "",
}, '*');
}
if (window.global_context.anchor) {
document.location.href = "about:srcdoc#" + window.global_context.anchor;
}
}
}, false);