onclick - Javascript code turned function, does not work -
onclick - Javascript code turned function, does not work -
i found js code on-the-line:
var encodeduri = encodeuri(csvcontent); var link = document.createelement("a"); link.setattribute("href", encodeduri); link.setattribute("download", "my_data.csv"); link.click(); and when run it, generates my_data.csv , downloads me, looking alter when user clicks button, code runs.i tried turning function called testing() function testing() , have link this:
<a href="#" onclick="javascript:testing()">test</a> but when set code in function not work :( doing wrong?
the error in console says 'testing not defined'
here jsfiddle: http://jsfiddle.net/f6cwf/
you need this:
html:
<a id='btn' href='#'>test</a> javascript:
document.queryselector( '#btn' ).addeventlistener( 'click', function () { var encodeduri = encodeuri( csvcontent ); var link = document.createelement( 'a' ); link.setattribute( 'href', encodeduri ); link.setattribute( 'download', 'my_data.csv' ); link.click(); }); also, create fiddle help out.
javascript onclick download
Comments
Post a Comment