in the previous SO post , a solution was found to the problem of dynamically loading pages with embedded <script> tags. however, this was not a comprehensive solution, as I found. The script that breaks the code (view the previous post and its solution) looks something like this:
- svc.html -
<script type="text/javascript" src="/plugin.js" css="/plugin.css"></script> <script type="text/javascript"> plugin_method(); </script> <div id='inner'> dynamically loaded content </div>
where plugin.js looks the same as before, but contains a function definition for plugin_method .
The problem is that when a script node is added to the document:
target[0].appendChild(scriptNode);
code is not executed immediately. If (as in the previous post) on the svc.html page svc.html is only one script tag, everything is fine, but as soon as there is a second, $('script:last') in the plugin no longer indicates the correct script and, therefore, does not Loads a stylesheet.
in addition, the body of the second script tag seems to be executed before the search - in the code for the first, so the method call fails (because the function has not yet been defined).
I found a couple of links that I am considering:
http://requirejs.org/docs/why.html http://unixpapa.com/js/dyna.html
anybody ideas?
source share