Solved

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

Posted on 2011-02-23
4
412 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

757 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

19 Experts available now in Live!

Get 1:1 Help Now