Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I turn off Google API I get an "Uncaught TypeError: Cannot read property 'DataTable' of undefined" message.

I would like to catch this undefined error and have a window popping up saying "Google has been disabled" but I'm not sure what typeof is undefined. I'm currently checking "DataTable" type but the window pops up regardless now.

Can someone help me please?

What I have tried:

Here is my code.


var data = new google.visualization.DataTable();
if(typeof DataTable == "undefined"){
window.alert("sometext");
} else {
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
data.addColumn('string', 'Type');
data.addColumn('string', 'Code');
data.addColumn('string', 'Aggregation');
data.addColumn('string', 'Stage');

data.addRows([
<xsl:apply-templates select="/*" mode="render"/>
['1','2','3','4','5','6','7']
]);

data.removeRow(data.getNumberOfRows() - 1);

drawDebugFlow(data);
}
Posted
Updated 28-Jul-17 5:40am

1 solution

You are getting the error before you put the if statement in so it won't help there. google.visualization is not loaded so therefore you get the error that DataTable cannot be read on undefined because visualization is undefined.

You can use a try catch to check for it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900