Javascript显示html页在阴影框一次
Javascript to show html paje in shadow box Once
我试图这样做,使用javascript我想在影子盒中显示HTML页面只有一次访问使用cookie的网站时,我怎么能做到这一点?HTML页面准备好了,但我想知道如何在阴影框中显示它使用javascript一次当用户访问网站??
如果你能帮我在阴影框中显示HTML页面只有那个伟大的
<!DOCTYPE html>
<html>
<head>
<style>
#ShadowBox {
width: 100px;
height: 100px;
display: block;
background-color: blue;
display:none;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
// function for clearing the cookkie
$("#ClearCookie").click(function(){
ClearCookie('visited');
});
//function for settinf the cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//function for reading cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
//For Setting the Cookie, you can call this onload or at the displaying of the shadowbox.
function MarkVisited() {
setCookie("visited", "visited", 10)
}
function ClearCookie(cname) {
setCookie("visited", "", 1)
}
//Put this in the document ready section. so it runs at onload
$( document ).ready(function() {
if (getCookie('visited') == "") {
$('#ShadowBox').show();
}
MarkVisited();
});
// On Load Section End
</script>
</head>
<body>
<div id="ShadowBox">
</div>
<button id="ClearCookie">Clear Cookie</button>
</body>
</html>
可以在显示阴影框时设置cookie
这是小提琴我已经在http://jsfiddle.net/gd7Xz/工作代码的工作提琴http://jsfiddle.net/G3XAb/
希望这对你有帮助,请勾选答案
<!DOCTYPE html>
<html>
<head>
<style>
#ShadowBox {
width: 100px;
height: 100px;
display: block;
background-color: blue;
display:none;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
//function for settinf the cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//function for reading cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
//For Setting the Cookie, you can call this onload or at the displaying of the shadowbox.
function MarkVisited() {
setCookie("visited", "visited", 10)
}
function ClearCookie(cname) {
setCookie(cname, "", 1)
}
//Put this in the document ready section. so it runs at onload
$(document).ready(function() {
if (getCookie('visited') == "") {
$('#ShadowBox').show();
}
MarkVisited();
});
// On Load Section End
</script>
</head>
<body>
<div id="ShadowBox"></div>
<button id="ClearCookie" onClick="ClearCookie('visited')">Clear Cookie</button>
</body>
</html>
相关文章:
- Javascript返回值只在循环中返回一次
- Jquery FadeIn FadeOut 只工作一次
- Javascript html每点击一次就会更改url
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Rails操作只调用一次,但我在ajax中每秒钟都调用一次
- jQuery滚动功能只工作一次
- 刷新导致我的帖子“;张贴“;再一次
- 引导程序崩溃一次只能看到一个
- 有没有一个抽象层,这样我就可以集成一次,然后使用pusher、pubnub或faye
- 加载器组件仅加载一次
- 根据Angular.JS上一次的内容禁用选择
- 一次又一次地在新的和相同的选项卡中打开一个url
- 只在宽度以下和宽度以上各准备一次
- 如果30秒未单击,请应用CSS一次,将其删除,然后重新迭代
- Angularjs:空对象,当只有一次点击时
- 在Angular应用程序中每个帖子投票一次
- 主干模型更改事件只触发一次
- 使用每500ms运行一次的jquery函数是个好主意吗
- For循环在Jquery中只运行一次
- Javascript显示html页在阴影框一次