HTML/Jquery Code to create sound
notification:
<script language="javascript">
var beep = (function () {
var ctx = new(window.audioContext ||
window.webkitAudioContext);
return function (duration, type, finishedCallback) {
duration = +duration;
// Only
0-4 are valid types.
type = (type % 5) || 0;
if (typeof finishedCallback != "function")
{
finishedCallback = function () {};
}
var osc
= ctx.createOscillator();
osc.type = type;
osc.connect(ctx.destination);
osc.noteOn(0);
setTimeout(function
() {
osc.noteOff(0);
finishedCallback();
}, duration);
};
})();
document.getElementsByTagName("button")[0].addEventListener("click", function
() {
var button
= this;
button.disabled = true;
beep(1000, 2, function
() {
button.disabled = false;
});
});
</script>
<button type="button">Beep!</button>
No comments:
Post a Comment