Javascript: "load" and "beforeunload" events not working

I am trying to use SimonLammer’s anki-persistence to achieve the following:

  1. On the front side, there is a <textarea> element, in which I will input some text.
  2. Upon the page-flip button being clicked (should trigger the “beforeunload” event), we will use anki-persistence to store the text that will be in the text box.
  3. Upon the DOM being loaded on the back side, we will retrieve the stored content and bestow it onto another element.

document.onload = pycmd('ans'); flips the card to the back side, so “onload” works at least to this extent.

However, the following simple test does not work

document.onload = function() {
  var box = document.getElementById("sentences");
  box.innerText = "text";
};

Why?

“beforeunload” also seems to do nothing.

A number of clients are implemented by keeping a long running webpage and dynamically updating parts of it as cards are reviewed

1 Like

You may want to try something like this here:

function WaitForLoad()
{
    if (document.readyState === "complete")
    {
        iteratefront();
				 console.log("Sucessfully loaded!")
    }
    else
    {
        setTimeout(WaitForLoad, 99);
    }
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.