Access hypeDocument from the innerHTML

<script> tags within inner HTML are executed in the global/window scope and thus do not have a hypeDocument object – it is the same if you were executing on the head.

You can reference it via HYPE.documents["documentName"] (though this is dependent on your export) or capture the global variable at an early time such as On Document Load with head HTML code that would look like this:

<script>
  function myCallback(hypeDocument, element, event) {
    window.hypeDocument = hypeDocument;
  }

  if("HYPE_eventListeners" in window === false) {
    window.HYPE_eventListeners = Array();
  }
  window.HYPE_eventListeners.push({"type":"HypeDocumentLoad", "callback":myCallback});

 </script>

(I’d probably recommend a name change for window.hypeDocument in this case, but that’s the idea)

2 Likes