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>

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


    //成功一定有方法,失败一定有原因。
  • 相关阅读:
    SQL 中文排序方式
    ASP.NET公有六种验证控件
    CustomValidator的使用方法
    c# 获取网页源码
    asp.net mvc 从客户端中检测到有潜在危险的 Request.Form 值的解决方法
    C#上传文件转字节流形式
    byte数组转换成文件保存到本地
    检测到有潜在危险的Request.Form值
    字节数组生成图片
    Edit Distance (编辑距离) .NET 实现
  • 原文地址:https://www.cnblogs.com/webapi/p/2415301.html
Copyright © 2011-2022 走看看