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
Post a Comment