View Single Post
Old 02-14-2021, 10:18 PM   #1
jrv
Junior Member
jrv began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Feb 2021
Device: none
window.load event: works in editor but not in viewer

I created a simple .epub page below using the calibre editor. In the calibre editor (ebook-edit) preview the code runs as I expect, with both text items appended to the <p> tag. In atril document viewer the code runs as I expect. In the calibre viewer (ebook-viewer) the first event fires and the text is appended but the second does not seem to fire. I tried different formulations to catch the window.load event, but none worked. I need to use the window.load event because I need to wait for some referenced code to load. I am new to programming epub files, so this may be the result of a misunderstanding on my part. Is this a bug in the ebook-viewer which I should report or some error on my part? I am running calibre version 5.10.1 on debian bullseye, linux 5.10.0-1-amd64. I found the same behavior using calibre on ubuntu.

JR

Code:
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
  <title>calibre onload</title>
  <script><![CDATA[
    document.addEventListener('DOMContentLoaded', (event) => {
      var txt = document.createTextNode(' This text was added to the <p> in the DOMContentLoaded event.');
      document.getElementById('the-content').appendChild(txt);
    } );
    window.onload = (event) => {
    var txt = document.createTextNode(' This text was added to the <p> in load event.');
    document.getElementById('the-content').appendChild(txt);
  }
  ]]></script>
</head>
<body>
  <h1>calibre onload</h1>
  <p id="the-content">static content.</p>
</body>
</html>
jrv is offline   Reply With Quote