Suppose, I have my webpage (say, index.html
) in my server root (say htdocs
). I’d like to load the Hype document in the webpage (the resources folder is also in htdocs) at a specific event (say window.onload
).
For the above (example) use case, I tried to load the document like this:
<html>
<head>
<style>
.HYPE_document
{
margin: auto;
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
<script>
window.onload = function()
{
var container = document.createElement("DIV");
container.setAttribute('class', 'HYPE_document');
container.setAttribute('id', 'filename_hype_container');
var docScript = document.createElement("SCRIPT");
docScript.setAttribute('type', 'text/javascript');
docScript.setAttribute('charset', 'utf-8');
docScript.setAttribute('src', 'myresourcesfolder/filename_hype_generated_script.js');
container.appendChild(docScript);
document.body.appendChild(container);
}
</script>
</head>
<body>
</body>
</html>
However, this doesn’t seem to work. I get an error:
Uncaught TypeError: Cannot read property 'setAttribute' of null at Array.m (filename_hype_generated_script.js:formatted:7)
at HYPE-654.thin.min.js:102
at HYPE-654.thin.min.js:102
at HYPE-654.thin.min.js:102
I checked those files and found out this being highlighted as the problematic part: document.getElementById(g).setAttribute("HYP_dn", f);
which is straightforward, and means that no element with the specified ID exists in the DOM.
So, I’d like to ask, if and how can I load the document at a specific event in some other HTML page without including the <script>
from the start?