mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Before this fix, browsing history didn't work at all. Now it mostly works but there are still some quirks that must be debugged further. Since session history handling turns out to be a rather complex topic (see https://html.spec.whatwg.org/multipage/history.html) the work in that direction will be postponed until other features reach a comparable level of readiness.
64 lines
2.1 KiB
HTML
64 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>ZIM Viewer</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
</head>
|
|
|
|
<body style="margin:0">
|
|
<div id=taskbar style="background:#bbffbb">Taskbar</div>
|
|
|
|
<iframe id="content_iframe"
|
|
referrerpolicy="same-origin"
|
|
onload="handle_content_url_change()"
|
|
src="skin/blank.html" title="ZIM content" width="100%"
|
|
style="border:0px">
|
|
</iframe>
|
|
|
|
<script>
|
|
|
|
// Terminology
|
|
//
|
|
// user url: identifier of the page that has to be displayed in the viewer
|
|
// and that is used as the hash component of the viewer URL. For
|
|
// book resources the address url is {book}/{resource} .
|
|
//
|
|
// iframe url: the URL to be loaded in the viewer iframe.
|
|
|
|
function userUrl2IframeUrl(url) {
|
|
return `/content/${url}`;
|
|
}
|
|
|
|
function iframeUrl2UserUrl(url) {
|
|
return url.split('/').slice(2).join('/');
|
|
}
|
|
|
|
const cf = document.getElementById('content_iframe');
|
|
cf.height = window.visualViewport.height - cf.offsetTop - 4;
|
|
|
|
function handle_location_hash_change() {
|
|
const hash = window.location.hash;
|
|
const iframeContentUrl = userUrl2IframeUrl(hash.slice(1));
|
|
console.log("handle_location_hash_change: " + hash);
|
|
if ( iframeContentUrl != cf.contentWindow.location.pathname ) {
|
|
cf.contentWindow.location.replace(iframeContentUrl);
|
|
}
|
|
}
|
|
|
|
window.onhashchange = handle_location_hash_change;
|
|
handle_location_hash_change();
|
|
|
|
function handle_content_url_change() {
|
|
document.title = cf.contentDocument.title;
|
|
const iframeContentUrl = cf.contentWindow.location.pathname;
|
|
console.log('handle_content_url_change: ' + iframeContentUrl);
|
|
const newHash = '#' + iframeUrl2UserUrl(iframeContentUrl);
|
|
const viewerURL = location.origin + location.pathname + location.search;
|
|
window.location.replace(viewerURL + newHash);
|
|
};
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|