我想完成一个
当点关闭浏览器时,让其收藏我的页面(如果已收藏就不用再收藏了),怎么实现呀,
注:
1要当用户关窗口时,才调用,
2.用户已收藏时,不用再收藏 可能要用cookie
这二个条件也要实现呀,
谢谢
当点关闭浏览器时,让其收藏我的页面(如果已收藏就不用再收藏了),怎么实现呀,
注:
1要当用户关窗口时,才调用,
2.用户已收藏时,不用再收藏 可能要用cookie
这二个条件也要实现呀,
谢谢
调试欢乐多
function book()
{
if(readCookie("book")!="yes")
{
saveCookie("book","yes",1);
window.external.AddFavorite(地址字符串, 说明字符串);
}
}function saveCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000))// cookie保存时间
var expires = "; expires="+date.toGMTString()
}
else expires = ""
document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
var nameEQ = name + "="
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,c.length)
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
}
return null
}
</script>
<body onUnload="book()">
</body>
window.external.AddFavorite(地址字符串, 说明字符串);
换成 window.external.AddFavorite(document.URL,document.title);
可当我关闭页面时,没有收藏呀,代码没起到任何反应,再帮帮试下,谢谢
{
window.external.AddFavorite(document.URL,document.title);
}
这样可实现 关闭时 弹出可用户收藏的效果
可我想实现当用户已收藏了页面时,不要再弹出收藏的窗口,当用户没有收藏页面时,才弹出让其收藏的窗口
谢谢大家
function saveCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000))
var expires = "; expires="+date.toGMTString()
}
else expires = ""
document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
var nameEQ = name + "="
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,c.length)
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
}
return null
}
加入cookie就行了
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页特效|Linkweb.cn/Js|---进入页面时提示加入收藏夹</title>
</head><body> <SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 7;url = "http://linkweb.cn/js";
title = "网页特效";// Cookie code from The JavaScript Source
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" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
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;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite (url,title);
}
else {
var msg = "Don't forget to book us!";
if(navigator.appName == "Netscape") msg += " (CTRL-D)";
alert(msg);
}
}
else {
count++;
SetCookie('count', count, exp);
}
}
checkCount();
// End -->
</script></body></html>
完整版
{
if (event.clientX>document.body.clientWidth && event.clientY<0 ||event.altKey)
{
if(getCookie(document.title)==null || getCookie(document.title)=="" )
{
SetCookie(document.title,document.URL);
window.external.AddFavorite(document.URL,document.title);
}
}
}