embedding javascript into google visualization table HTML cell

64 views
Skip to first unread message

c2billp

unread,
Jul 22, 2011, 2:12:13 PM7/22/11
to Google Visualization API
hello:

i'm trying to render the cell content within a google vis table to
call an onClick event.

currently:
,{v:'<A target=_new HREF=page.html>click here</A>'}"

i'd like this to be:

,{v:'<A onclick="window.open('popup.html', 'windowname1', 'width=200,
height=77'); return false;" target=#>click here</A>'}


I'm having trouble sorting out how to escape the " chars so that this
string works. Any help/suggestions?

Thank you.
bill

asgallant

unread,
Jul 26, 2011, 1:19:38 PM7/26/11
to google-visua...@googlegroups.com
You escape quotes in javascript with the backslash:

,{v:'<A onclick="window.open(\'popup.html\', \'windowname1\', \'width=200, height=77\');  return false;" target=#>click here</A>'}

You might be better served using the selection event handler to do what you want though.  After drawing your table (assuming you named your viz table object "myTable"), call this:

google.visualization.events.addListener(myTable, 'select', function () {
     window.open("popup.html", "windowname1", "width=200, height=77");
});

Harry Chang

unread,
Jun 17, 2013, 11:04:44 AM6/17/13
to google-visua...@googlegroups.com
This is exactly what I want to do. Can you show a complete code example? I copy your code in table.setCell(....) but it did not work. Thanks. - Harry
Reply all
Reply to author
Forward
0 new messages