4

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.
pushkin
  • 9,575
  • 15
  • 51
  • 95
NealWalters
  • 17,197
  • 42
  • 141
  • 251

4 Answers4

10

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
  • This doesn't work anymore. You have to use the new JS library described in the answer by Whitehat here: https://stackoverflow.com/questions/45829721/google-charts-a-parser-blocking-cross-site-is-invoked-via-document-write – Sujay Phadke Jul 15 '19 at 08:58
9

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'.

pushkin
  • 9,575
  • 15
  • 51
  • 95
greggian
  • 351
  • 2
  • 5
  • This can easily happen e.g. when Wordpress template uses google but before including google api and after that includes the same second time - just comment the first appearance and keep the one AFTER the google api include :) – jave.web Aug 23 '13 at 17:26
5

you should include this script -- http://www.google.com/jsapi

java
  • 51
  • 1
  • 2
5

I had the problem, but I was using:

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

It was solved by chanching the line to:

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

sibidiba
  • 6,270
  • 7
  • 40
  • 50