当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 兼容FF的设为首页与收藏网站的JS代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 兼容FF的设为首页与收藏网站的JS代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 370 ::
收藏到网摘: n/a

今天某同学改版某首页..发现以前在页面上用的设为首页与收藏本站的代码在FF下不起作用…..狂汗…..

于是人肉搜索一翻后得到了较好的支持代码.嘻嘻,好东西,大家分享!

代码如下:

<script>
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, “”);
        }
        catch (e)
        {
            alert(”加入收藏失败,请使用Ctrl+D进行添加”);
        }
    }
}
function SetHome(obj,vrl){
        try{
                obj.style.behavior=’url(#default#homepage)’;obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege(”UniversalXPConnect”);
                        }
                        catch (e)  {
                                alert(”此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为’true’”);
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref(’browser.startup.homepage’,vrl);
                 }
        }
}
</script>
<a href=”javascript:void(0);” target=”_self” onClick=”javascript:AddFavorite(’http://www.ruanchen.com/'软晨学习网’)” >收藏</a>
<a href=”javascript:void(0);” target=”_self” onclick=”SetHome(this,’http://www.ruanchen.com’)”>设为首页</a>

浏览器多,很多HMTL,CSS,JS.的写法都有些差异,希望这段代码能帮助有需要的同学,以后改版有此类功能可参考!咔咔.