www.webdeveloper.com
Results 1 to 4 of 4

Thread: External Javascript File

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    External Javascript File

    Hi guys, I'm relatively new to javascript, so this may be an easy answer.
    I am using the Google Places & Maps API's to create a javascript based webpage.

    All I need to know, is if it is possible to reference an external library (e.g. the places library from a javacript file as opposed to in the html page in script tags)?

    The google documentation (http://code.google.com/apis/maps/doc...pt/places.html) recommends to put the reference in a script tag in the webpage like so:
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true_or_false"></script>
    but seeing as all my workings are in an external javascript file (mapstuff.js) which my .jsp references, how do i reference the Google library from my mapstuff.js?

    Thanks in advance,
    Ross.

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    753
    I don't know that I fully understand the dilemma here. If you include multiple javascript files as you have shown using <script> like in the case of:
    Code:
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true_or_false"></script>
    Then all of the included .js files can 'work together' calling upon the functions, variables and classes from each of the other .js files. The only thing that would matter is functions or code that is executed before another(or all) external .js files are loaded.


    The only way to actually include a javascript file from within another javascript file is to use something like AJAX to grab the file and then eval() the returned code. However I think it's a better idea to just have it loaded from within HTML as it requires less code, less time and will give you the same result.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Nov 2011
    Posts
    2
    Thanks for the reply man.
    So if I load the google library from my webpage, all my other external .js's will be able to access the library's functions provided the external one is loaded afterward the google one?

  4. #4
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    753
    Quote Originally Posted by rossrossp View Post
    ...
    So if I load the google library from my webpage, all my other external .js's will be able to access the library's functions provided the external one is loaded afterward the google one?
    That is correct. You will be able to call any of the functions or variables from the google .js library from your own external .js files. The order in which they are loaded matters but it seems you understood that part as well so I don't think I need to explain.

    Good luck.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles