I'm showing Google's charts in some web pages. But I can't assure my clients will have network access to Google: a client computer will be in the same LAN as my web server (which can access Google), but I'm not guaranteed all the clients will have access outside the LAN.

I'd like to show data using Google Charts to those clients who can access it, and a plain HTML table to those who don't.

I tried setting a variable to false, and changing it to true in a method called when the Google Visualization API is loaded:

var canAccessGoogleVisualizationVar = false;
google.load('visualization', '1', {packages: ['corechart'], callback: canAccessGoogleVisualization});
function canAccessGoogleVisualization() 
{
    canAccessGoogleVisualizationVar = true;
}

But it doesn't seem to work.

How can I know from the client side if the Google Visualization is accesible or not?


Update: The code above didn't work because of the following code (which I didn't post before as I thought wasn't meaningful):

google.setOnLoadCallback(drawVisualization);

function drawVisualization() 
{
    // Check if Google Visualization is loaded
    if (!canAccessGoogleVisualizationVar) {
        alert('Can't access Google Visualization');
    }

    // The following code can be any of the samples from Google (see http://code.google.com/apis/ajax/playground/?type=visualization#pie_chart).
    var data = new google.visualization.DataTable();
    // Add columns and values to data
    ...
    // Call new google.visualization.AnyChartBuilderFromTheAPI(<element>).draw(data);
}

I noticed my code didn't work because, if canAccessGoogleVisualizationVar == true, the if branch isn't taken, and if its false, the function drawVisualization() wouldn't have been executed.

So I took the if-test outside the function:

google.setOnLoadCallb
Edit
Report