Mert METİN
Mert METİN

Reputation: 1288

setTimeout does not work - what is wrong ?

i need to work with setTimeout function but that function does not work. First of all,

  Player.prototype.playByUrl = function (url) {
        this.object.data = url;
        return this.play();
    }

Above code is my function and i call it

window.onload = function () {
        player = new Player('playerObject');
        setTimeout(player.playByUrl($mp4Link),3000);
    }

However, in above code, setTimeout does not work why ?

Upvotes: 1

Views: 150

Answers (3)

William Isted
William Isted

Reputation: 12322

I had an issue with setTimeout() where the function needed to be in quotes. Try:

window.onload = function () {
    player = new Player('playerObject');
    setTimeout("player.playByUrl($mp4Link)",3000);
}

Upvotes: 1

Afshin Mehrabani
Afshin Mehrabani

Reputation: 34919

You should use a function or a string:

setTimeout(function(){
              player.playByUrl($mp4Link)
           },3000);

OR

setTimeout("player.playByUrl($mp4Link)",3000);

Upvotes: 1

Naftali
Naftali

Reputation: 146302

setTimeout needs a function:

setTimeout(function(){player.playByUrl($mp4Link)},3000);

The way you were doing it was that it was executing player.playByUrl($mp4Link) immediately on the start of the script.

Upvotes: 5

Related Questions