Joshua
Joshua

Reputation: 1

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.createNotification("", "title", "mmm").show();
    setTimeout(timedout(), 10000);
}

timedout();
</script>

Please help :(

Upvotes: 0

Views: 690

Answers (2)

user578895
user578895

Reputation:

try:

function timedout(){ ... }
setInterval(timedout, 10000);

Your code calls timedout() immediately (twice) instead of trying to run it every 10 seconds.

Upvotes: 5

ariel
ariel

Reputation: 16140

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);

Upvotes: 1

Related Questions