js 首次进入弹窗

今天有个需求,首次进入需要弹窗,然后就在网上找了下,虽然看了很多但是说的都不是我想要的,最后终于到了一个合适的。

function get_cookie(Name) {
    var search = Name + "=";
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            // if cookie exists
            offset += search.length;
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1)
                end = document.cookie.length;
            returnvalue=decodeURI(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}
setTimeout(function(){
    if (get_cookie("popped")==""){
        document.cookie="popped=yes";
        alert('弹窗');
    }
},2000);
原文地址:https://www.cnblogs.com/mica/p/11162546.html