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


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 相关文章推荐
JavaScript中getUTCMinutes()方法的使用详解
Jun 10 Javascript
JQuery实现样式设置、追加、移除与切换的方法
Jun 11 Javascript
限制文本框只能输入数字||只能是数字和小数点||只能是整数和浮点数
May 27 Javascript
浅谈jquery中的each方法$.each、this.each、$.fn.each
Jun 23 Javascript
AngularJS 输入验证详解及实例代码
Jul 28 Javascript
简单理解js的prototype属性及使用
Dec 07 Javascript
js实现横向拖拽导航条功能
Feb 17 Javascript
vue.js中过滤器的使用教程
Jun 08 Javascript
javascript+html5+css3自定义弹出窗口效果
Oct 26 Javascript
原生JS与jQuery编写简单选项卡
Oct 30 jQuery
Vue 路由 过渡动效 数据获取方法
Jul 31 Javascript
微信小程序动态设置图片大小的方法
Nov 21 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
php下实现伪 url 的超简单方法[转]
2007/09/24 PHP
php 在windows下配置虚拟目录的方法介绍
2013/06/26 PHP
php pki加密技术(openssl)详解
2013/07/01 PHP
使用php显示搜索引擎来的关键词
2014/02/13 PHP
php自动识别文件编码并转换为UTF-8的方法
2014/06/12 PHP
如何解决phpmyadmin导入数据库文件最大限制2048KB
2015/10/09 PHP
JavaScript语法着色引擎(demo及打包文件下载)
2007/06/13 Javascript
解析js中获得父窗口链接getParent方法以及各种打开窗口的方法
2013/06/19 Javascript
JavaScript判断文件上传类型的方法
2014/09/02 Javascript
原生js页面滚动延迟加载图片
2015/12/20 Javascript
从零学习node.js之文件操作(三)
2017/02/21 Javascript
JavaScript实现构造json数组的方法分析
2018/08/17 Javascript
layui-table表复选框勾选的所有行数据获取的例子
2019/09/13 Javascript
vue+layui实现select动态加载后台数据的例子
2019/09/20 Javascript
javascript设计模式之迭代器模式
2020/01/30 Javascript
jQuery实现简易聊天框
2020/02/08 jQuery
jquery实现上传文件进度条
2020/03/26 jQuery
谈谈node.js中的模块系统
2020/09/01 Javascript
JS数组转字符串实现方法解析
2020/09/04 Javascript
Python 文件重命名工具代码
2009/07/26 Python
详解Python 数据库 (sqlite3)应用
2016/12/07 Python
Windows下Anaconda的安装和简单使用方法
2018/01/04 Python
通过python检测字符串的字母
2020/02/18 Python
Python3标准库之dbm UNIX键-值数据库问题
2020/03/24 Python
Python 如何批量更新已安装的库
2020/05/26 Python
python实现企业微信定时发送文本消息的示例代码
2020/11/24 Python
台湾深度自由行旅游平台:Tripbaa趣吧
2017/10/10 全球购物
请说出你所知道的线程同步的方法
2013/04/19 面试题
领导党性分析材料
2014/02/15 职场文书
护士求职信范文
2014/05/24 职场文书
中标通知书
2015/04/17 职场文书
正确使用MySQL INSERT INTO语句
2021/05/26 MySQL
python中的装饰器该如何使用
2021/06/18 Python
Golang 语言控制并发 Goroutine的方法
2021/06/30 Golang
联想win10摄像头打不开怎么办?win10笔记本摄像头打不开解决办法
2022/04/08 数码科技
Win11无法访问设备和打印机 如何解决页面空白
2022/04/09 数码科技