javascript - External JS sometimes doesnt loads in time? -


<!doctype html> <html> <head> <script type="text/javascript" src="a.js"></script> </head> <body> <script> functionfromajs(); </script> </body>     </html> 

this works ok of time, on production server, not 100%. says functionfromajs() doesnt exists, ok, if .js not gets loaded in time. do?

edit: using window.onload function should not difference long script you're embedding loaded before function call. a.js file loaded before <script>functionfromajs();</script> anyway , should able execute function if exists.

try using:

<script>    window.onload = function() {       functionfromajs();    }; </script> 

so function not called before document loaded. or if you're using jquery can use:

<script>        $(document).ready(function() {       functionfromajs();    }); </script> 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -