Solved

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

Posted on 2011-02-23
4
414 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:
gurvinder372 earned 250 total points
ID: 34963091
use body onload event

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

Assisted Solution

by:Proculopsis
Proculopsis earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now