zoukankan      html  css  js  c++  java
  • 设为首页、加入收藏 兼容代码

    一般写法:

    <a href="javascript:window.external.AddFavorite(window.location.href,document.title)">加入收藏</a>

    <a href="javascript:void()" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(location.href);">设为首页</a>

    说明:这种写法是最常见的,兼容性不高

     

    兼容写法:

    <a onclick="AddFavorite(window.location,document.title)" href="javascript:void(0)">加入收藏</a>

    <a onclick="SetHome(window.location)" href="javascript:void(0)">设为首页</a>

    <script type="text/javascript" language="javascript">

     

    //加入收藏

    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(url)

    {

         if (document.all)

        {

           document.body.style.behavior='url(#default#homepage)';

           document.body.setHomePage(url);

     

        }

        elseif (window.sidebar)

        {

            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',url);

         }

    }

    </script>

    说明:这种写法兼容性是比较高的

    jquery超级交流群:36780982

    阅读全文
    类别:jquery/js 查看评论

    //成功一定有方法,失败一定有原因。
  • 相关阅读:
    android工程下assets与raw文件夹
    eclipse增加jar包方式对比
    跳出内循环,继续下一次外循环的写法
    ImportError: cannot import name 'BaseDataset' from 'src.dataset'
    神经网络中的反向传播法
    Pytorch中ndarray tensor list互转
    Python运行语法错误:IndentationError: unindent does not match any outer indentation level
    module 'torch' has no attribute 'gesv'
    极大似然估计
    Gaussian Processes
  • 原文地址:https://www.cnblogs.com/webapi/p/2116031.html
Copyright © 2011-2022 走看看