document.cookie/setCookie not working on Safari and IE

允我心安 提交于 2019-12-13 00:45:44

问题


I am trying to play music from last end point after each page is loaded. This example not working on Safari and IE but working fine on firefox,opera and chrome. Is possible to replace this with jquery cookie plugin and how?

<audio preload="auto" src="a.mp3" loop="true" autobuffer autoplay="true">
    Unsupported in Firefox
    </audio>

    <script>

    function setCookie(c_name,value,exdays)
    {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value;
    }

    function getCookie(c_name)
    {
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++)
        {
          x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
          y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
          x=x.replace(/^\s+|\s+$/g,"");
          if (x==c_name)
            {
            return unescape(y);
            }
          }
    }

    var song = document.getElementsByTagName('audio')[0];
    var played = false;
    var tillPlayed = getCookie('timePlayed');
    function update()
    {
        if(!played){
            if(tillPlayed){
            song.currentTime = tillPlayed;
            song.play();
            played = true;
            }
            else {
                    song.play();
                    played = true;
            }
        }

        else {
        setCookie('timePlayed', song.currentTime);
        }
    }
    setInterval(update,1000);
    </script>

来源:https://stackoverflow.com/questions/31231222/document-cookie-setcookie-not-working-on-safari-and-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!