[转] [教程]flash设为首页和加入收藏夹功能的实现

在网上很多都是as2的方法,这个事as3的。
不必多说看代码   也可以去我的博客看 http://www.flasham.com/blog
js代码
function SetHome()
{

var aUrls=document.URL.split("/");
var vDomainName="http://" + aUrls[2] + "/";

if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(vDomainName);
}
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', vDomainName);
}
}


function bookmark()
{
var title=document.title;
var url=document.location.href;
if (window.sidebar)
{
window.sidebar.addPanel(title, url, "");
}
else if (window.opera)
{
var mbm=document.createElement('a');
mbm.setAttribute('rel', 'sidebar');
mbm.setAttribute('href', url);
mbm.setAttribute('title', title);
mbm.click();
}
else if (window.external)
{
window.external.AddFavorite(url, title);
}
else
{
alert('Unfortunately, your browser does not support this action,please bookmark this page manually by pressing Ctrl + D on PC or Cmd + D on Mac.');
}
}


然后是flash中调用

设为主页
ExternalInterface.call(“SetHome”);
添加到收藏夹
ExternalInterface.call(“bookmark”);

你可能感兴趣的:(浏览器,Security,Opera,Blog,Flash)