Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can you make sure all javascript librarys imported into html have loaded

Posted on 2011-02-23
4
Medium Priority
?
423 Views
Last Modified: 2012-05-11
Hello Experts,

I am calling a google javascript function in my code:

var decodedPoints = google.maps.geometry.encoding.decodePath(encodedPoints) ;

However, earlier in my code, I call the library:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false"></script>

What appears to be happening is that if the library has fully downloaded then my line of javascript is erroring. Does anyone know how to put a test in there which forces the library to be loaded before the javascript can be called (or only call the javascript ones the library has loaded)?

Many Thanks
0
Comment
Question by:jagku
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1000 total points
ID: 34963091
use body onload event

<body onload="alert('all scripts loaded')">
0
 
LVL 20

Assisted Solution

by:Proculopsis
Proculopsis earned 1000 total points
ID: 34968654

//Try waiting for the dom to be ready by enclosing your code in the following event handler:

  window.onload  = function() {
    var decodedPoints = google.maps.geometry.encoding.decodePath(encodedPoints) ;
  };

0
 

Author Comment

by:jagku
ID: 34968862
Hi,

Thanks for the replies.
Just to clarify that the decodedPoints... statement is part of a larger function which I am calling when users hit radio buttons on my site (this piece of codes draws lines on a map depicting a route).

Therefore would the following work or should the onload function only be called separately?

function xx()
{
 .
.
.
 window.onload  = function() {
    var decodedPoints = google.maps.geometry.encoding.decodePath(encodedPoints) ;
  };
.
.
.
}
0
 

Author Closing Comment

by:jagku
ID: 34968927
Hi,
Please ignore my last point.
Also, the best solution is both answers (but I can only choose one - so I chose the first response).

Many Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question