html - How to play sound when a value is changed in a dynamic javascript table? -
i have dynamic table auto-refreshes every 5 seconds, created using javascript. want play notification sound when value in 'failed column' increases. can't frame strategy go it. can me this? in advance.
this ajaxcall
ajaxcall = function () { $.get('/c/web/jas/getdetails', function (data) { var jsondata=json.parse(data); generatetable(data); settimeout('ajaxcall()', 5000); }); };
this table function
generatetable = function (json) { var ar = json.parse(json); var col = new array(); (var = 0; < ar.length; i++) { (var key in ar[i]) { if (col.indexof(key) === -1) { col.push(key); } } } var table = document.createelement("table"); table.border = "1"; var tr = table.insertrow(-1); (var = 0; < col.length; i++) { var th = document.createelement("th"); th.innerhtml = col[i]; tr.appendchild(th); } (var = 0; < ar.length; i++) { tr = table.insertrow(-1); (var j = 0; j < col.length; j++) { var tabcell = tr.insertcell(-1); tabcell.innerhtml = ar[i][col[j]]; } } var dvtable = document.getelementbyid("dvtable"); dvtable.innerhtml = ""; dvtable.appendchild(table); }
you can use web audio api generate sound in browser. has reasonably good support (apart in ie).
the web audio api provides source node called oscillatornode allows frequencies generated against specified waveform.
for example, make small, dull beep (something approaching warning sound in example) do:
const context = new audiocontext(); const oscillatornode = context.createoscillator(); oscillatornode.type = 'triangle'; oscillatornode.frequency.value = 150; oscillatornode.connect(context.destination); oscillatornode.start(); oscillatornode.stop(context.currenttime + 0.5);
here, triangle
predefined waveform can specified via instance's type
property , frequency
determines pitch. specify duration argument stop()
(in case, half second).
audionodes cheap create, design of web audio api encourages developers recreate them , when they’re needed. means in case, of in code handles updating dom increase values in failed column.
this informative reference web audio api if you'd read more, or see more practical examples: web audio api: add bandwidth-friendly sound web page
Comments
Post a Comment