第一次点击页面弹出收藏夹提示框代码,谁知道呀?
发布网友
发布时间:2022-04-26 13:30
我来回答
共1个回答
热心网友
时间:2022-06-28 15:50
主要是利用客户端的JavaScript代码(Cookies功能)控制,您说的情况是指同一台电脑上首次运行该网页时弹出收藏夹提示框。
如果本地电脑的Cookies被清空后,再次运行该网页则仍会弹出,这就是实现的原理,参考代码如下:
<script>
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
//设置cookies时间,任意值。
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count');
if(count == null) {
SetCookie('count','1')
return 1
}
else{
var newcount = parseInt(count) + 1;
if(newcount<2) count=1;
SetCookie('count',newcount,exp);
return newcount
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function setBookmark(){
Bookmark_Add(document.title)//document.title为对应网页的标题
}
if(amt()==1)
{
setBookmark()
}
//-->
</script>