Javascript Google Chrome desktop notification
I'm currently trying to create a Javascript script that makes a new Google desktop notification every 10 seconds but my webpage constantly loads and spams notifications. What am I doing wrong?
<script type="text/javascript">
function timedout(){
webkitNotifications.createNoti开发者_JAVA百科fication("", "title", "mmm").show();
setTimeout(timedout(), 10000);
}
timedout();
</script>
Please help :(
try:
function timedout(){ ... }
setInterval(timedout, 10000);
Your code calls timedout() immediately (twice) instead of trying to run it every 10 seconds.
The parameter for setInterval/setTimeout have to be the function name without (), or a string containing the code that will be eval'd. For your use, you can use setInterval which will call the function every X milliseconds.
function timedNotification() {
webkitNotifications.createNotification("", "title", "mmm").show();
}
setInterval("timedNotification()", 10000);
精彩评论