javascript - building script tags that load in order and accept variables -
in code below instead of using
<script src="" ></script
i building script up. enable me insert client , calc names - i.e. add variables src calling. leads js errors scripts not loaded in @ right time/ order.
here code
<script type="text/javascript"> var client = 'test'; var calc = 'loancalculator'; var insertscript = function(src){ var element= document.getelementsbytagname('head')[0]; var script= document.createelement('script'); script.type= 'text/javascript'; script.src= src; element.appendchild(script); } var insertscriptcontent = function(code){ var element= document.getelementsbytagname('body')[0]; var script= document.createelement('script'); script.type= 'text/javascript'; script.innerhtml = code; element.appendchild(script); } insertscript('http://test.com.au/clients/' + client +'/web/'+calc+'/calculator-lib.js'); insertscript('http://test.com.au/api/configeditor/213?callback=setupconfig'); insertscript('http://test.com.au/clients/' + client +'/web/javascripts/c-app.js'); insertscriptcontent('var __loancalculator = null; var calculator = null; var loadtool = function(){ __loancalculator = abcd("abcd.loancalculator"); var container = $(".loan-calculator-app"); container.empty(); calculator = new __loancalculator.loancalculatorapp(container); calculator.init(); };'); </script> <script type="text/javascript"> $(document).ready(function(){ loadtool(); }); </script>
is there way load top libraries , document .ready runs when these loaded? or there better way add these variables in?
thanks
scripts can loaded @ begining of rendering of page. it's not possible load them when page loaded. can define them in head , call them in specific order.
Comments
Post a Comment