检查 cookie 无需重新加载

Check cookie with no reloading

我需要找到在函数结束后删除 onclick 的方法,或者查看 coockie livetime 或者如果您有其他建议,我会在这里听取。

我想在功能失败或成功后做,onclick="play()"不重新加载页面就不会再弹出。 我的代码:

    <script>
function setCookie(cname,cvalue,exdays){var d=new Date();d.setTime(d.getTime()+(exdays*24*60*60*1000));var expires="expires="+d.toUTCString();document.cookie=cname+"="+ cvalue+"; "+ expires+ ";domain=.SDS.net;path=/";}
function getCookie(cname){var name=cname+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1);}
if(c.indexOf(name)==0){return c.substring(name.length,c.length);}}return"";}   
 var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
 var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);  
var installed = getCookie("installed");
var failed = getCookie("failed");
    if (failed == '3') {
   
    } else {
           if (installed == '') {
         if(isChrome && !isMobile){
        function play(){
        alert('Download Extension bla bla bla ');
        chrome.webstore.install('https://chrome.google.com/webstore/detail/ID',success, fail);
        }
        }
    }
    }
 
   
    function fail(){
        setCookie("failed",3,232323)
        console.log('Coockie Failed Updated');
   location.reload();


 
    }
   
    function success(){
        setCookie("installed",1,232323);
        console.log('Coockie Installed Updated');
  location.reload();

       
    }
   
 
 
</script>
<div class="test" onclick="play()"></div>

试试这个

$(".test").prop("onclick", null);