我尝试在IE中关闭网页之前添加书签,但是失败了,它只是不会弹出添加书签框。有人能告诉我什么是错的吗?这是我的代码,谢谢。
<script type="text/javascript">
function ConfirmClose(e)
{
var evtobj=window.event? event : e;
if(evtobj == e)
{
//firefox
if (!evtobj.clientY)
{
var r=confirm("Bookmark me?");
if (r==true)
{
window.sidebar.addPanel(document.title, location.href, "");
}
else
{
window.close();
}
}
}
else
{
//IE
if (evtobj.clientY < 0)
{
var r=confirm("Bookmark me?");
if (r==true)
{
window.external.AddFavorite(location.href, document.title); // <---- this won't work. but work when i write this in <a> tag
}
else
{
window.close();
}
}
}
}
</script>
我在body标签中调用此ConfirmClose,如下所示: -
<body onbeforeunload="ConfirmClose(event)">
p / s:我知道这很烦人,但这是我的客户要求的。我确实添加了一个按钮供用户点击它,如果他们想要书签。