js添加收藏夹
怎么用js把网页添加到收藏夹,要ie,火狐都支持,给分多多啊
------解决方案--------------------function AddFav(u, t) {
if (document.all) {
window.external.AddFavorite(u, t)
} else{
window.sidebar.addPanel(t, u, "")
}
return false
};
<a href="" onclick="return AddFav('http://dotnet.aspx.cc/','.net');">add</a>
------解决方案--------------------<script>
function addfavorite()
{
if (document.all)
{
window.external.addFavorite('http://www.XXX.com','XXX);
}
else if (window.sidebar)
{
window.sidebar.addPanel('XXX, 'http://www.XXX.com', "");
}
}
</script>
<a href="#" onclick="addfavorite()">XXX</a>
------解决方案--------------------function setHomepage(){ // 设置首页
var url=window.location.href;
if (document.all){
document.body.style.behavior = 'url(#default#homepage)';
document.body.setHomePage(url);
}else if (window.sidebar){
if (window.netscape){
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch (e) {
alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
}
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', url);
}
}
function addFavorite()//添加收藏
{
var sURL=window.location.href;
var sTitle='XXXX系统';
try {
window.external.addFavorite(sURL, sTitle);
}
catch (e)
{
try
{
window.sidebar.addPanel(sTitle, sURL, "");
}
catch (e)
{
alert("加入收藏失败,请手动添加.");
}
}
}
------解决方案--------------------if(window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel )){//Firefox
window.sidebar.addPanel(title,url,'');
}else if( document.all && "object" == typeof( window.external )){//IE
window.external.addFavorite(url,title);
}else{
alert("请您手工添加...");
}