ThalesMiguel
ThalesMiguel

Reputation: 194

Load Javascript on runtime created Bootstrap Modal

I have this view where I call a Modal that loads from a external html file. Since the content of this Modal is generated in runtime, I have to load/reload my javascript files, right?

I've created a function that reloads my javascript files after this Modal is loaded and it works fine.

My Question: Is there any better way to accomplish this?

Upvotes: 0

Views: 603

Answers (1)

Francisco Goldenstein
Francisco Goldenstein

Reputation: 13767

Have you tried to load a JS file when the external html file is included?

In the view:

<script>LoadJsAsync('/Scripts/modal-scriptName.js');</script>

In a JS file that is referenced:

function LoadJsAsync(jsPath) {
    var head = document.getElementsByTagName('body')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.onreadystatechange = function () {
        // if (this.readyState == 'complete') { callFunctionFromScript(); }
    }
    script.src = jsPath;
    head.appendChild(script);
}

Upvotes: 1

Related Questions