gpt4 book ai didi

Javascript 在阴影框中显示 html paje 一次

转载 作者:行者123 更新时间:2023-11-28 08:23:26 25 4
gpt4 key购买 nike

我正在尝试使用 javascript 来做到这一点,我想在使用 cookie 访问网站时仅在影子框中显示 HTML 页面一次,我该如何做到这一点? 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

这是我做过的 fiddle http://jsfiddle.net/gd7Xz/代码的工作 fiddle 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 在阴影框中显示 html paje 一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22708161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com