Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 87242  / 14 Years ago, mon, april 5, 2010, 12:00:00

I would like to use an external javascript file in another javascript file. For example, I could store all my global variables in a globals.js file and then call then from the website logic logic.js. Then in the index.html, i would insert the tag. How do I use the globals.js inside the logic.js?


More From » javascript

 Answers
11

Javascript doesn't have any implicit include this other file mechanisms, like css's @include. You just have to list your globals file before the logic file in the tags:



 <script type=text/javascript src=globals.js />
<script type=text/javascript src=logic.js />


If guaranteeing that the globals are available before anything in the logic file fires up, you can do a slow polling loop to see if some particular variable is available before calling an init() or whatever function.


[#97155] Thursday, April 1, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zaynerogerb

Total Points: 454
Total Questions: 109
Total Answers: 97

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
zaynerogerb questions
;