如何只向第一次访问者显示横幅?
How to only display banner to first time visitor?
我的网站上有这个文字横幅。我希望它只向使用 cookie 的新访客显示。我对 JS 知之甚少,所以请帮助我如何只向初次访问者展示它。
我在 Discourse-based this Android forum site 上使用它,它已经建立在 Node.js.
上
<style>
.top {
background: linear-gradient(to right, #141517, #6A9113);
border-radius: 10px;
font-size: 20px;
color: white;
opacity: 0.9;
text-align: center;
padding: 25px;
line-height: 30px;
margin: 10px 0px 30px 0px;
}
</style>
<div class="top">
Welcome to the forum. This is demo text.
</div>
获取此代码:
.top
默认应该是 display: none;
$(document).ready(function() {
var visited = $.cookie("visited")
if (visited == null) {
$('.top').show();
alert($.cookie("visited"));
}
$.cookie('visited', 'yes', { expires: 1, path: '/' });
});
这是完整的代码...
工作演示 https://jsfiddle.net/hdas2012/6yjo346k/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<div class="top">
<h2>You will only see it once</h2>
Welcome to the forum. This is demo text.
</div>
<script>
$(document).ready(function(){
if(!$.cookie('welcomeMsg')){
$(".top").show();
$.cookie('welcomeMsg', 'Y', { expires: 365*3 });
}
});
</script>
<style>
.top {
background: linear-gradient(to right, #141517, #6A9113);
border-radius: 10px;
font-size: 20px;
color: white;
opacity: 0.9;
text-align: center;
padding: 25px;
line-height: 30px;
margin: 10px 0px 30px 0px;
display: none;
}
</style>
我的网站上有这个文字横幅。我希望它只向使用 cookie 的新访客显示。我对 JS 知之甚少,所以请帮助我如何只向初次访问者展示它。
我在 Discourse-based this Android forum site 上使用它,它已经建立在 Node.js.
上<style>
.top {
background: linear-gradient(to right, #141517, #6A9113);
border-radius: 10px;
font-size: 20px;
color: white;
opacity: 0.9;
text-align: center;
padding: 25px;
line-height: 30px;
margin: 10px 0px 30px 0px;
}
</style>
<div class="top">
Welcome to the forum. This is demo text.
</div>
获取此代码:
.top
默认应该是 display: none;
$(document).ready(function() {
var visited = $.cookie("visited")
if (visited == null) {
$('.top').show();
alert($.cookie("visited"));
}
$.cookie('visited', 'yes', { expires: 1, path: '/' });
});
这是完整的代码... 工作演示 https://jsfiddle.net/hdas2012/6yjo346k/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<div class="top">
<h2>You will only see it once</h2>
Welcome to the forum. This is demo text.
</div>
<script>
$(document).ready(function(){
if(!$.cookie('welcomeMsg')){
$(".top").show();
$.cookie('welcomeMsg', 'Y', { expires: 365*3 });
}
});
</script>
<style>
.top {
background: linear-gradient(to right, #141517, #6A9113);
border-radius: 10px;
font-size: 20px;
color: white;
opacity: 0.9;
text-align: center;
padding: 25px;
line-height: 30px;
margin: 10px 0px 30px 0px;
display: none;
}
</style>