Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 弹出窗口和Cookies_Javascript_Html_Jquery_Css_Cookies - Fatal编程技术网

Javascript 弹出窗口和Cookies

Javascript 弹出窗口和Cookies,javascript,html,jquery,css,cookies,Javascript,Html,Jquery,Css,Cookies,我正在尝试创建一个弹出窗口,如“请选择业务或消费者”上的 现在我要做的是弹出窗口: 1:设置当用户离开我们的站点时过期的cookie。 2:当他们在我们店里时,弹出窗口只显示一次。 3:privat将我们的客户重定向到我们的b2c商店。 4:“模式”>Erhverv关闭弹出窗口,让客户留在我们的b2b商店 这就是我到目前为止所得到的,我不确定我是否做对了 HTML 爪哇 (功能(){ “严格使用” var cookieName='tplCookieConsent';//cookie名称 var

我正在尝试创建一个弹出窗口,如“请选择业务或消费者”上的

现在我要做的是弹出窗口: 1:设置当用户离开我们的站点时过期的cookie。 2:当他们在我们店里时,弹出窗口只显示一次。 3:privat将我们的客户重定向到我们的b2c商店。 4:“模式”>Erhverv关闭弹出窗口,让客户留在我们的b2b商店

这就是我到目前为止所得到的,我不确定我是否做对了

HTML

爪哇 (功能(){ “严格使用”

var cookieName='tplCookieConsent';//cookie名称
var cookieLifetime=365;//Cookie过期天数
/**
*放一块饼干
*@param cname-cookie名称
*@param cvalue-cookie值
*@param exdays-到期日(天)
*/
var_setCookie=函数(cname、cvalue、exdays){
var d=新日期();
d、 设置时间(d.getTime()+(exdays*24*60*60*1000));
var expires=“expires=“+d.toutString();
document.cookie=cname+“=”+cvalue+”;“+expires+”;path=/”;
};
/**
*拿块饼干
*@param cname-cookie名称
*@返回字符串
*/
var_getCookie=函数(cname){
变量名称=cname+“=”;
var ca=document.cookie.split(“;”);
对于(变量i=0;i
<div class="modal fade cookieModal" id="cookieModal" tabindex="-1" role="dialog" aria-labelledby="cookieModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<h3>Vælg venligst erhverv eller privat. </h3><p>Ved valget af privat, vil du blive omdirigeret til vores b2c shop homebarista.dk</p>
           
</div>
<div class="modal-footer">
<button id="cookieModalConsent" type="button" class="btn btn-primary" data-dismiss="modal">Erhverv</button>
<a href="https://www.homebarista.dk/" class="btn btn-primary" role="button" aria-disabled="true">Privat kunde</a>
          
</div>
</div>
</div>
</div
.btn{
background: #ff710f;
color: #ffffff;
border: 0;
padding: 10px 20px;
text-align: center;
cursor: pointer;
font-family: Oswald;
font-weight: normal;
font-size: 16px;
text-transform: uppercase;
display: inline-block;
}

.cookieModal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 99999;
opacity: 0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.cookieModal:target {
opacity: 1;
pointer-events: auto;
}
.cookieModal > div {
width: 35%;
margin: 50px auto;
font-family: Oswald;
line-height: 24px;
padding: 30px;
text-align: center;
position: relative;
border-radius: 10px;
background: #fff;
background: #ec6608;
}
var cookieName = 'tplCookieConsent'; // The cookie name
var cookieLifetime = 365; // Cookie expiry in days

/**
* Set a cookie
* @param cname - cookie name
* @param cvalue - cookie value
* @param exdays - expiry in days
*/
var _setCookie = function (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=/";
};

/**
* Get a cookie
* @param cname - cookie name
* @returns string
*/
var _getCookie = function (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 "";
};

/**
* Should the cookie popup be shown?
*/
var _shouldShowPopup = function () {
if (_getCookie(cookieName)) {
return false;
} else {
return true;
}
};

// Show the cookie popup on load if not previously accepted
if (_shouldShowPopup()) {
$('#cookieModal').modal('show');
}

// Modal dismiss btn - consent
$('#cookieModalConsent').on('click', function () {
setCookie(cookieName, 1, cookieLifetime);
});

})();    

</script>