Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-23
4
Medium Priority
?
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

715 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