js 實現 設置首頁,添加收藏功能,兼容IE/ff

<li><a
                        href="javaScript:AddFavorite(window.location,document.title)"
                        style="cursor: hand">加入收藏</a></li>
                    <li><a href="javaScript:SetHome(window.location)"
                        style="cursor: hand">設爲首頁</a></li>


<script>


//

function AddFavorite(sURL, sTitle) {

                    try {
                        window.external.addFavorite(sURL, sTitle);
                    } catch (e) {
                        try {
                            window.sidebar.addPanel(sTitle, sURL, "");
                        } catch (e) {
                            $.msg.alert("加入收藏失敗,請使用Ctrl+D進行添加");
                        }
                    }
                }
                //設爲首頁

                function SetHome(url){
                    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){
                                $.msg.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', url);
                    }

                }


</script>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章