在body中给onbeforeunload加入js方法,该js方法就是添加收藏。但是现在感觉ie9(应该说从ie8开始)安全机制方面提升,所以以下代码会提示没有权限,而如果页面有一个加入收藏的按钮,是没有问题的,有人有好的方法吗?而且要验证该机器是否已经把这个站点加入收藏,这个验证也需要一定的权限,感觉也可行性也很低,有兄弟姐妹有好的解决方案么?<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testMsg.aspx.cs" Inherits="CeairPortal.B2E.Web.testMsg" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function addBook() {
var url = "#";
var title = "aaa";
if (window.sidebar) {
window.sidebar.addPanel(title, url, "");
} else if (document.all) {
alert("欢迎下次光临");
window.external.AddFavorite(url, title);
} else if (window.opera && window.print) {
}
}
//document.onmousedown=click;
</script>
<script type="text/javascript">
function xxx() {
// if(document.body.clientWidth-event.clientX< 170&&event.clientY< 0||event.altKey)
// {
// top.location.href="logout.cmd?method=logout";
window.external.AddFavorite('http://#', 'XX网');
alert("欢迎下次光临");
// }
}
</script>
</head>
<body onbeforeunload="addBook();">
<form id="form1" runat="server">
<div>
<input type="button" onclick="xxx();" title="aaaa" value="aaa" />
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function addBook() {
var url = "#";
var title = "aaa";
if (window.sidebar) {
window.sidebar.addPanel(title, url, "");
} else if (document.all) {
alert("欢迎下次光临");
window.external.AddFavorite(url, title);
} else if (window.opera && window.print) {
}
}
//document.onmousedown=click;
</script>
<script type="text/javascript">
function xxx() {
// if(document.body.clientWidth-event.clientX< 170&&event.clientY< 0||event.altKey)
// {
// top.location.href="logout.cmd?method=logout";
window.external.AddFavorite('http://#', 'XX网');
alert("欢迎下次光临");
// }
}
</script>
</head>
<body onbeforeunload="addBook();">
<form id="form1" runat="server">
<div>
<input type="button" onclick="xxx();" title="aaaa" value="aaa" />
</div>
</form>
</body>
</html>
这是第一个问题,现在就是提示“没有权限”,ie6好像是可以,但现在ie9不行
我提的这个方法不能完美的解决你的需求。只能尽量的实现目的初衷。
假如你的网站被用户从收藏夹删除,我想那也没必要再提醒他收藏了。在你不能直接访问收藏夹的时候,只能退而求其次了。
或许你可以去获取用户收藏夹的目录,然后在目录里去遍历是否有你的收藏值。
需要自己写代码了。
userdata的用意我明白。后面说的去获取用户收藏夹的目录,刚了解到这个功能的时候我就怀疑过:这属于用户的隐私,1是拿不到,2是即便拿到了,也会对用户的隐私构成威胁。
可以学习一下一些porn sites的做法,页面上放一个有吸引力的按钮
btw,activex也是绕不过需要用户确认这一关的。
不用去判断用户有没有收藏过。在用户第一次浏览网站(判断有无cookie)时,页面中加个tooltip气泡提示,让用户自己决定要不加收藏就可以了。