Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 38
How to filter by key press ? 6 54
Any Way to rotate banner ads from Commission Junction? 2 36
Two decimal 5 25
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

685 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