-4

I have this JavaScript function

/* Use this method to send a message to the active chatwindow */
function sendMessageToActiveWindow(message) {
  swfobject.getObjectById('lightIRC').sendMessageToActiveWindow(message);
}

I want to set up an array of messages and then every X minutes use sendMessageToActiveWindow(message) with a randomly selected message from the array.

Is it possible to do such a thing in JavaScript/jQuery etc. and any examples?

user3973427
  • 1,435
  • 3
  • 16
  • 20

1 Answers1

5

Sure, how about:

setInterval(function() {
    var message = messages[Math.floor(Math.random()*messages.length)]
    sendMessageToActiveWindow(message)
}, 60000);

This will pick a random message from the messages array and fire your method, every minute.

tymeJV
  • 103,943
  • 14
  • 161
  • 157