Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google.load - and message "google is not defined"

What do I need to include to do a google.load() statement? I'm getting the error:

google is not defined

Based on this page, I thought I should add this:

<script type="text/javascript"
        src="http://www.google.com/jsapi?key=ABCDEFG">
</script>

But when I did, I got this error:

"window.LoadFirebugConsole" is not a function.
like image 628
NealWalters Avatar asked Nov 28 '22 12:11

NealWalters


2 Answers

I had the same problem and solved it like this:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type='text/javascript'>
    function LoadGoogle()
    {
        if(typeof google != 'undefined' && google && google.load)
        {
            // Now you can use google.load() here...
        }
        else
        {
            // Retry later...
            setTimeout(LoadGoogle, 30);
        }
    }

    LoadGoogle();
</script>

The idea is to retry until google is defined.

The other solutions didn't help me, probably because this piece of code is loaded via Ajax from another page.

like image 182
Pang Avatar answered Dec 14 '22 23:12

Pang


Did you include the google jsapi script before adding the load and callback methods? They should be in seperate script blocks.

<script src="http://www.google.com/jsapi?key=ABCDE"></script>
<script type="text/javascript">        
    google.load("jquery", "1");

    // Define our onLoad callback
    function OnLoad(){
      alert("Loaded!");
    }

    google.setOnLoadCallback(OnLoad);
</script>

There are additional examples in the Google's 'AJAX Api's Playground'.

like image 24
greggian Avatar answered Dec 14 '22 22:12

greggian