// JavaScript Document
// 加入收藏 < a onclick="AddFavorite(window.location,document.title)" >加入收藏< /a>

function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败,请使用Ctrl+D进行添加");
        }
    }
}
//设为首页 < a onclick="SetHome(this,window.location)" > 设为首页 < /a>
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);
                 }
        }
}

使用
< a  href="#" onclick="SetHome(this,window.location)" > 设为首页 < /a>
< a  href="#" onclick="AddFavorite(window.location,document.title)"> 收藏本站 < /a>

兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面的更多相关文章

  1. 完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码

    <script  type="text/javascript"> //设为首页 function SetHome(obj,url){     try{         ...

  2. 设为首页 和 收藏本站js代码 兼容IE,chrome,ff

    设为首页 和 收藏本站js代码 兼容IE,chrome,ff //设为首页 function SetHome(obj,url){ try{ obj.style.behavior='url(#defau ...

  3. 设为首页/加入收藏JS代码

    传统网站常用的设为首页/加入收藏js代码 <a href="javascript:void(0)" onclick="sethome(this,window.loc ...

  4. javascript 设为首页 | 加入收藏夹 JS代码

    我们介绍一个可兼容所有浏览器的加入收藏代码代码,大概原理是这样的我们根据获取用户navigator.userAgent.toLowerCase()信息来判断浏览器,根据浏览器是否支持加入收藏js命令, ...

  5. JS代码实现网站设为首页加入收藏功能

    <script language="javascript"> //加入收藏 function AddFavorite(sURL, sTitle) { try { win ...

  6. js代码 设为首页 加入收藏

    // JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...

  7. JS代码:设为首页 加入收藏

    // JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...

  8. HTML设为首页/加入收藏代码

    (特别注意:要把'这个符号换成无任何输入法状态中输入的'这个符号,否则程序无法运行)   1.文字型:     <a onclick="this.style.behavior='url ...

  9. ASP.NET中怎样将页面设为首页,加入收藏

    1.文字js脚本事件:<span onClick="var strHref=window.location.href;this.style.behavior=’url(#default ...

随机推荐

  1. 204. Count Primes 统计<n的质数的个数

    [抄题]: Count the number of prime numbers less than a non-negative number, n. [暴力解法]: 时间分析: 空间分析: [优化后 ...

  2. 前端学习笔记2017.6.21-html和浏览器的关系以及开发工具

    html文档是一种文件格式, 浏览器可以识别这种文件格式,并能把html文档里面的内容解析出来. 用更贴近程序员的话说就是:html相当于c语言,浏览器相当于c编译器. 开发工具用sublime te ...

  3. 算法Sedgewick第四版-第1章基础-004一封装交易对象

    1. package ADT; /****************************************************************************** * Co ...

  4. 对private protected public的详解:

    #include <iostream> #include <stack> #include <queue> #include <exception> # ...

  5. Django扩展Auth-User表的几种方法

    方式1, OneToOneField from django.contrib.auth.models import Userclass UserProfile(models.Model): user ...

  6. Servlet入门第二天

    1. GenericServlet: 1). 是一个 Serlvet. 是 Servlet 接口和 ServletConfig 接口的实现类. 但是一个抽象类. 其中的 service 方法为抽象方法 ...

  7. Netty服务端的业务流程分析

    Netty的服务端怎么和java NIO联系起来的,一直很好奇这块内容,这里跟下代码,下篇文章看下Channel相关的知识. finalChannelFuture initAndRegister(){ ...

  8. css中设置div水平居中,margin:0px auto没用的情况

    在CSS中加了margin:0px auto;却没有效果,不能实现居中的问题!margin:0px auto;意思就是:上下边界为0,左右根据宽度自适应!就是水平居中的意思.无效的原因是,当你没有设置 ...

  9. 解决Spring MVC 对AOP不起作用的问题

    用的是 SSM3的框架 Spring MVC 3.1 + Spring 3.1 + Mybatis3.1 第一种情况: Spring MVC 和 Spring 整合的时候,SpringMVC的spri ...

  10. PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)

    1095 解码PAT准考证/1153 Decode Registration Card of PAT(25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级: ...