2014-12-04 68 views
0

我需要幫助來了解如何使用javascript更新值cookie「currenttime」。 我想設置當前顯示電影的時間。我用videojs(http://www.videojs.com/),並有一個函數來獲取當前的時間,它看起來像這樣:使用javascript設置cookie「currenttime」

var whereYouAt = myPlayer.currentTime(); 

但我不知道如何設置這個值的cookie。我試試這個:

videojs("video1").ready(function(){ 
    var myPlayer = this; 

    function setCookie(cvalue) { 

    document.cookie = "cookiessss" + "=" + cvalue; 
} 
var whereYouAt = myPlayer.currentTime(); 
setCookie(whereYouAt); 
}); 

但是在播放電影的過程中它不會改變cookie的值。

回答

0

這隻會執行一次。您可以爲timeupdate添加一個事件偵聽器,該偵聽器將在視頻前進時觸發。

myPlayer.on('timeupdate', function(){ 
    var whereYouAt = myPlayer.currentTime(); 
    setCookie(whereYouAt); 
});