Rumah >hujung hadapan web >tutorial js >添加到收藏夹代码(兼容几乎所有的浏览器)_典型特效

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

WBOY
WBOYasal
2016-05-16 19:21:571301semak imbas

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

复制代码 代码如下:

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

  
     addbookmark cross all browser - http://www.never-online.net 
    
    
    
    
    
    
    <script> <BR> //<![CDATA[ <BR> /* <BR> * Copyright 2006 Dynamic Site Solutions. <BR> * Free use of this script is permitted for non-commercial applications, <BR> * subject to the requirement that this comment block be kept and not be <BR> * altered. The data and executable parts of the script may be changed <BR> * as needed. Dynamic Site Solutions makes no warranty regarding fitness <BR> * of use or correct function of the script. Terms for use of this script <BR> * in commercial applications may be negotiated; for this, or for other <BR> * questions, contact "license-info@dynamicsitesolutions.com". <BR> * <BR> * Script by: Dynamic Site Solutions -- http://www.dynamicsitesolutions.com/ <BR> * Last Updated: 2006-08-03 <BR> */ <br><br> //IE5+/Win, Firefox, Netscape 6+, Opera 7+, Safari, Konqueror 3, IE5/Mac, iCab 3 <br><br> var addBookmarkObj = { <BR> init:function() { <BR> if(!document.getElementById || !document.createTextNode) return; <BR> var cont=document.getElementById('addBookmarkContainer'); <BR> if(!cont) return; <BR> var a=document.createElement('a'); <BR> a.href=location.href; <BR> if(!window.opera) { // this doesn't work in Opera 7+ if the link has an <BR> // onclick handler, so we only add it if the browser isn't Opera. <BR> a.onclick=function() { <BR> addBookmarkObj.exec(this.href,this.title); <BR> return false; <BR> } <BR> } <BR> a.rel='sidebar'; // this makes it work in Firefox and Opera 7+ <BR> a.title=document.title; <BR> a=cont.appendChild(a); <BR> a.appendChild(document.createTextNode('Bookmark This Page')); <BR> }, <BR> exec:function(url, title) { <BR> var isKonq=(isLikelyKonqueror3 && isLikelyKonqueror3()); <BR> var isMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1); <BR> var buttonStr = isMac?'Command/Cmd':'CTRL'; <br><br> if(window.external && (!document.createTextNode || <BR> (typeof(window.external.AddFavorite)=='unknown'))) { <BR> // IE4/Win generates an error when you <BR> // execute "typeof(window.external.AddFavorite)" <BR> // In IE7 the page must be from web server, not directly from a local <BR> // file system, otherwise, you get a permission denied error. <BR> window.external.AddFavorite(url, title); // IE/Win <BR> } else if(isKonq) { <BR> alert('You need to press CTRL + B to bookmark our site.'); <BR> } else if((window.sidebar && <BR> (navigator.userAgent.toLowerCase().indexOf('firefox')!=-1)) || <BR> (window.opera && opera.buildNumber && !isNaN(opera.buildNumber()))) { <BR> void(0); // do nothing here (Firefox or Opera 7+) <BR> } else if(window.opera) { // older Opera <BR> alert('You need to press '+buttonStr+' + T to bookmark our site.'); <BR> } else if(window.home) { // Netscape, iCab <BR> alert('You need to press '+buttonStr+' + D to bookmark our site.'); <BR> } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0 <BR> alert('You need to press Command/Cmd + D to bookmark our site.'); <BR> } else { <BR> alert('In order to bookmark this site you need to do so manually '+ <BR> 'through your browser.'); <BR> } <BR> } <BR> } <br><br> function isLikelyKonqueror3() { <BR> if(!document.getElementById) return false; <BR> if(document.defaultCharset || window.opera || !window.print) return false; <BR> if(window.home) return false; /* Konqueror doesn't support this but Firefox, <BR> which has silent support for document.all when in Quirks Mode does */ <BR> if(document.all) return true; // Konqueror versions before 3.4 <BR> var likely = 1; <BR> // testing for silent document.all support; try-catch used to keep it from <BR> // generating errors in other browsers. <BR> // try-catch causes errors in IE4 so we use the eval() to hide it. <BR> // try { <BR> // var str=document.all[0].tagName; <BR> // } catch(err) { likely=0; } <BR> eval("try{var str=document.all[0].tagName;}catch(err){likely=0;}"); <BR> return likely; <BR> } <br><br> function dss_addEvent(el,etype,fn) { <BR> if(el.addEventListener && (!window.opera || opera.version) && <BR> (etype!='load')) { <BR> el.addEventListener(etype,fn,false); <BR> } else if(el.attachEvent) { <BR> el.attachEvent('on'+etype,fn); <BR> } else { <BR> if(typeof(fn) != "function") return; <BR> var tempFunc = el['on'+etype]; <BR> el['on'+etype] = function() { <BR> if(typeof(tempFunc) == "function") tempFunc(); <BR> fn(); <BR> } <BR> } <BR> } <br><br> dss_addEvent(window,'load',addBookmarkObj.init); <BR> //]]> <BR> </script>
  
  
    

 cross-browser addBookmark 

by www.dynamicsitesolutions.com

    

      

      

 demonstration 


      

      
    
    

     
  


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn