When a user closes a
, hide that
on all site pages

前端 未结 12 936
忘了有多久
忘了有多久 2020-12-15 02:49

I\'ve developed a couple of alert boxes that display on all site pages.

The user is able to close each box separately:

12条回答
  •  悲&欢浪女
    2020-12-15 03:51

    Try this solution jsfiddle and read comments regarding storage path. If you are working on sub domain then you have to specify domain in cookie written like in setCookie() comments. if you are working on localhost then the cookie-domain must be set to "" or NULL or FALSE instead of "localhost". For domain reference you can study this stackoverflow question

    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 + ";path=/";
        // document.cookie = cname + "=" + cvalue + ";" + expires + ";domain=.example.com;path=/"; if you are trying in any sub-domain
    } 
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i = 0; i 

提交回复
热议问题