I have a long script webpack output, lets call it bla.js
In my main html file I'm trying to open bla.js on button click. this is how I tried to do it:
<body>
<button class="btn-start" type="button" onclick="clickHandler()"></button>
<script>
function clickHandler(){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "scrs/bla.js";
document.head.appendChild(script);
}
</script>
</body>
but on button click nothing happens although In application tab of google chrome developer tools I can see that the bla.js script gets added!
And when I do it like this:
<body>
<button class="btn-start" type="button" onclick="window.location.href='run_bla.html';">
</button>
</body>
and in the run_bla.html:
<body>
<script src='scrs/bla.js'></script>
</body>
it works perfectly fine! the only problem is in the second way there will be a /run_bla.html at the end of the url and I don't want that.
So what is wrong with the first way? How can I open the script without website url changes? any idea what is the problem? I'm stuck with this for a while...