JS plugin namespace question

  • Hi.
    I am trying to load from js plugin an API. Everything loading but, I i can't access to namespace of the loaded API.
    for example let's take this:

    Code
    function loadAPI(){
        var script = document.createElement("script");
        script.src = "http://www.google.com/jsapi?key=YOUR_API_KEY_HERE&callback=loadMaps";
        script.type = "text/javascript";
        document.getElementsByTagName("head")[0].appendChild(script); }

    and i can't acces to namespace of the google maps. How it must be coded?

  • Hi,

    in your example code above the 'loadMaps' function would need to be defined at the 'window' object,

    e.g.
    window.loadMaps = function(){ ... }

    (btw - to avoid conflicts I would recommend generating an unique function name and using that).

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!