添加到收藏夹代码(兼容几乎所有的浏览器)


Posted in Javascript onJanuary 09, 2007

兼容IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Konqueror 3, IE5/Mac, 还有 iCab 3.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head> 
    <title> addbookmark cross all browser - http://www.never-online.net </title> 
    <meta http-equiv="ImageToolbar" content="no" /> 
    <meta name="author" content="never-online, BlueDestiny"/> 
    <meta name="keywords" content="never modules, Mozilla CSS, C#, .net, Reference, BlueDestiny, never-online"/> 
    <meta name="description" content="addbookmark cross all browser, javascript reference, c sharp artilces"/> 
    <meta name="creator.name" content="never-online, BlueDestiny" /> 
    <style type="text/css" media="all" title="Default"> 
      body { 
        color: windowtext;  
        background: appworkspace; 
        font-family: Arial; 
        font-size:9pt; 
        line-height:150%; 
      } 
      h1, h2, h3, h4 { 
        color:#fff; 
        font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; 
      } 
      a { 
        color:#fff; 
      } 
      div#header { 
        text-align:center; 
        color:#eee; 
      } 
      div#header a { 
        color:#fff; 
        font-weight:bold; 
      } 
      div#footer { 
        margin-top:10px; 
        text-align:center; 
        color:#eee; 
        font-size:8pt; 
      } 
      div#operator { 
        margin:20px 0 20px 0; 
      } 
      div#operator ul, div#operator li { 
        margin:0; 
        padding:0; 
      } 
      div#operator li { 
        display:inline; 
        list-style-type:none; 
        margin-right:5px; 
        margin-left:5px; 
        border:1px solid #000; 
        padding:5px; 
        color:#000; 
        background-color:#eee; 
        cursor:hand; 
        cursor:pointer; 
      } 
      hr { 
        margin:10px 0 10px 0; 
      } 
      div.wrapper { 
        text-align:center; 
      } 
      div.content { 
        border:1px solid #333; 
        background-color:buttonface; 
        color:#000; 
        padding:10px; 
        margin:10px 0 10px 0; 
        font-size:10pt; 
        line-height:150%; 
        text-align:left; 
        width:80%; 
        margin-left: auto; 
        margin-right: auto; 
        -moz-box-sizing:border-box; 
      } 
      div.content a { 
        color:#000; 
      } 
      div.content h4 { 
        color:#000; 
        margin-left:10px; 
        text-align:left; 
      } 
    </style> 
    <script type="text/javascript"> 
    //<![CDATA[ 
      /*  
      *  Copyright 2006 Dynamic Site Solutions. 
      *  Free use of this script is permitted for non-commercial applications, 
      *  subject to the requirement that this comment block be kept and not be 
      *  altered.  The data and executable parts of the script may be changed 
      *  as needed.  Dynamic Site Solutions makes no warranty regarding fitness 
      *  of use or correct function of the script.  Terms for use of this script 
      *  in commercial applications may be negotiated; for this, or for other 
      *  questions, contact "license-info@dynamicsitesolutions.com". 
      * 
      *  Script by: Dynamic Site Solutions -- http://www.dynamicsitesolutions.com/ 
      *  Last Updated: 2006-08-03 
      */       //IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Konqueror 3, IE5/Mac, iCab 3 
      var addBookmarkObj = { 
        init:function() { 
          if(!document.getElementById || !document.createTextNode) return; 
          var cont=document.getElementById('addBookmarkContainer'); 
          if(!cont) return; 
          var a=document.createElement('a'); 
          a.href=location.href; 
          if(!window.opera) { // this doesn't work in Opera 7+ if the link has an  
            // onclick handler, so we only add it if the browser isn't Opera. 
            a.onclick=function() { 
              addBookmarkObj.exec(this.href,this.title); 
              return false; 
            } 
          } 
          a.rel='sidebar'; // this makes it work in Firefox and Opera 7+ 
          a.title=document.title; 
          a=cont.appendChild(a); 
          a.appendChild(document.createTextNode('Bookmark This Page')); 
        }, 
        exec:function(url, title) { 
          var isKonq=(isLikelyKonqueror3 && isLikelyKonqueror3()); 
          var isMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1); 
          var buttonStr = isMac?'Command/Cmd':'CTRL'; 
          if(window.external && (!document.createTextNode || 
            (typeof(window.external.AddFavorite)=='unknown'))) { 
              // IE4/Win generates an error when you 
              // execute "typeof(window.external.AddFavorite)" 
              // In IE7 the page must be from web server, not directly from a local  
              // file system, otherwise, you get a permission denied error. 
              window.external.AddFavorite(url, title); // IE/Win 
          } else if(isKonq) { 
            alert('You need to press CTRL + B to bookmark our site.'); 
          } else if((window.sidebar && 
             (navigator.userAgent.toLowerCase().indexOf('firefox')!=-1)) || 
             (window.opera && opera.buildNumber && !isNaN(opera.buildNumber()))) { 
               void(0); // do nothing here (Firefox or Opera 7+) 
          } else if(window.opera) { // older Opera 
            alert('You need to press '+buttonStr+' + T to bookmark our site.'); 
          } else if(window.home) { // Netscape, iCab 
            alert('You need to press '+buttonStr+' + D to bookmark our site.'); 
          } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0 
            alert('You need to press Command/Cmd + D to bookmark our site.');     
          } else { 
            alert('In order to bookmark this site you need to do so manually '+ 
              'through your browser.'); 
          } 
        } 
      } 
      function isLikelyKonqueror3() { 
        if(!document.getElementById) return false; 
        if(document.defaultCharset || window.opera || !window.print) return false; 
        if(window.home) return false; /* Konqueror doesn't support this but Firefox,  
          which has silent support for document.all when in Quirks Mode does */ 
        if(document.all) return true; // Konqueror versions before 3.4 
        var likely = 1; 
        // testing for silent document.all support; try-catch used to keep it from 
        // generating errors in other browsers. 
        // try-catch causes errors in IE4 so we use the eval() to hide it. 
        // try { 
        //   var str=document.all[0].tagName; 
        // } catch(err) { likely=0; } 
        eval("try{var str=document.all[0].tagName;}catch(err){likely=0;}"); 
        return likely; 
      } 
      function dss_addEvent(el,etype,fn) { 
        if(el.addEventListener && (!window.opera || opera.version) && 
        (etype!='load')) { 
          el.addEventListener(etype,fn,false); 
        } else if(el.attachEvent) { 
          el.attachEvent('on'+etype,fn); 
        } else { 
          if(typeof(fn) != "function") return; 
          var tempFunc = el['on'+etype]; 
          el['on'+etype] = function() { 
            if(typeof(tempFunc) == "function") tempFunc(); 
            fn(); 
          } 
        } 
      } 
      dss_addEvent(window,'load',addBookmarkObj.init); 
    //]]> 
    </script> 
  </head> 
  <body id="www.never-online.net"> 
    <div id="header"><h1> cross-browser addBookmark </h1>by www.dynamicsitesolutions.com<hr/></div> 
    <div class="wrapper"> 
      <div class="content"> 
      <h4> demonstration </h4> 
      <div id="addBookmarkContainer"></div> 
      </div>     
    </div> 
    <div id="footer">collected by <a href="http://www.never-online.net">http://www.never-online.net</a></div> 
  </body> 
</html>
Javascript 相关文章推荐
简明json介绍
Sep 28 Javascript
artdialog的图片/标题以及关闭按钮不显示的解决方法
Jun 27 Javascript
AngularJS入门教程(一):静态模板
Dec 06 Javascript
详解AngularJS 模态对话框
Apr 07 Javascript
jQuery阻止移动端遮罩层后页面滚动
Mar 15 Javascript
Node.js Mongodb 密码特殊字符 @的解决方法
Apr 11 Javascript
jQueryUI Sortable 应用Demo(分享)
Sep 07 jQuery
JavaScript实现树的遍历算法示例【广度优先与深度优先】
Oct 26 Javascript
webpack 插件html-webpack-plugin的具体使用
Apr 09 Javascript
JS实现DOM节点插入操作之子节点与兄弟节点插入操作示例
Jul 30 Javascript
Vue2.2.0+新特性整理及注意事项
Aug 22 Javascript
js实现点击展开隐藏效果(实例代码)
Sep 28 Javascript
Web版彷 Visual Studio 2003 颜色选择器
Jan 09 #Javascript
一个对于js this关键字的问题
Jan 09 #Javascript
JS控件autocomplete 0.11演示及下载 1月5日已更新
Jan 09 #Javascript
根据分辩率调用不同的CSS.
Jan 08 #Javascript
如何用javascript判断录入的日期是否合法
Jan 08 #Javascript
[IE&amp;FireFox兼容]JS对select操作
Jan 07 #Javascript
javascript中的对象和数组的应用技巧
Jan 07 #Javascript
You might like
一个取得文件扩展名的函数
2006/10/09 PHP
php下通过IP获取地理位置的代码(小偷程序)
2011/06/09 PHP
搭建基于Docker的PHP开发环境的详细教程
2015/07/01 PHP
php如何控制用户对图片的访问 PHP禁止图片盗链
2016/03/25 PHP
深入浅析Yii admin的权限控制
2016/08/31 PHP
laravel 5.3 单用户登录简单实现方法
2019/10/14 PHP
PHP实现限制域名访问的实现代码(本地验证)
2020/09/13 PHP
网页中的图片的处理方法与代码
2009/11/26 Javascript
javascript Array.sort() 跨浏览器下需要考虑的问题
2009/12/07 Javascript
优化javascript的执行速度
2010/01/23 Javascript
JS中处理与当前时间间隔的函数代码
2012/05/23 Javascript
基于socket.io和node.js搭建即时通信系统
2014/07/30 Javascript
浅析js预加载/延迟加载
2014/09/25 Javascript
JavaScript箭头函数_动力节点Java学院整理
2017/06/28 Javascript
关于JavaScript中forEach和each用法浅析
2017/07/27 Javascript
jQuery轻量级表单模型验证插件
2018/10/15 jQuery
laydate时间日历插件使用方法详解
2018/11/14 Javascript
Node.js对MongoDB进行增删改查操作的实例代码
2019/04/18 Javascript
webpack打包html里面img后src为“[object Module]”问题
2019/12/22 Javascript
python通过zlib实现压缩与解压字符串的方法
2014/11/19 Python
一文带你了解Python中的字符串是什么
2018/11/20 Python
Python采集猫眼两万条数据 对《无名之辈》影评进行分析
2018/12/05 Python
python 实现selenium断言和验证的方法
2019/02/13 Python
pymysql模块的操作实例
2019/12/17 Python
python定义类self用法实例解析
2020/01/22 Python
matlab 计算灰度图像的一阶矩,二阶矩,三阶矩实例
2020/04/22 Python
python中os包的用法
2020/06/01 Python
python数据抓取3种方法总结
2021/02/07 Python
英国浴室洗脸盆购物网站:Click Basin
2018/06/08 全球购物
What's the difference between Debug and Trace class? (Debug类与Trace类有什么区别)
2013/09/10 面试题
Java程序开发中如何应用线程
2016/03/03 面试题
中层干部竞争上岗演讲稿
2014/01/13 职场文书
运动会稿件300字
2014/02/14 职场文书
电气工程自动化求职信
2014/03/14 职场文书
党章培训心得体会
2014/09/04 职场文书
2019年行政人事个人工作总结范本!
2019/07/19 职场文书