I have a function loadDays() that should be called when my body section is loaded:
<body onload="loadDays()">
My loadDays() function looks like this:
<script>
function loadDays() {
// Code
}
</script>
Inside of loadDays() I need to access an excel-file.
So I added src="https://requirejs.org/docs/release/2.3.5/minified/require.js" to the <script> tag.
But then I recieved the following error:
Uncaught ReferenceError: loadDays is not defined at onload
Then someone gave me the hint to use two different <script> tags:
<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js">
const Excel = require('exceljs');
</script>
<script>
function loadDays() {
// Code
}
</script>
But now I have the problem that it says:
Uncaught ReferenceError: Excel is not defined at loadDays
How can I solve this issue?
As an alternative, in your script you could use a 'DOMready' event :
https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
window.addEventListener('DOMContentLoaded', (event) => {
console.log('DOM fully loaded and parsed');
});
Everything inside this event will be executed once the full DOM is loaded
If you import well your script, that should do the trick