javascript - How to execute a js function onload? -
below functional , working code . when copy paste text file testfile.html
, open browser works fine.
but want selectcollege
function execute right after initviz
function
i tried
<body onload="initviz();selectcollege('engineering');"> . . .
but didn't work. how can make selectcollege
function execute right after initviz
?
<!doctype html> <html> <head> <title>select marks</title> <script type="text/javascript" src="https://public.tableau.com/javascripts/api/tableau-2.min.js"></script> <script type="text/javascript"> var viz, sheet; function initviz() { var containerdiv = document.getelementbyid("vizcontainer"), url = "http://public.tableau.com/views/regionalsampleworkbook/college", options = { "academic year": "", hidetabs: true, onfirstinteractive: function () { sheet = viz.getworkbook().getactivesheet(); } }; viz = new tableau.viz(containerdiv, url, options); } function selectcollege(college_name) { sheet.selectmarksasync("college", college_name, tableau.selectionupdatetype.replace); } </script> </head> <body onload="initviz();"> <div id="vizcontainer"></div> <br /> <button onclick="selectcollege('engineering');">select value</button> </body> </html>
in selectcollege()
attempting access sheet
before defined in callback function tableau.viz
options
object, namely onfirstinteractive()
. in order solve this, can call function after defining sheet
in function:
options = { ... onfirstinteractive: function () { sheet = viz.getworkbook().getactivesheet(); selectcollege('engineering'); } };
and according this forum, onfirstinteractive()
called once when instance of tableau.viz
first rendered.
Comments
Post a Comment