Home > Web Front-end > JS Tutorial > body text

Add to favorites effect implemented by js code and compatible with mainstream browsers_javascript skills

WBOY
Release: 2016-05-16 16:43:25
Original
1306 people have browsed it
//加入收藏 
function AddFavorite(){ 
  if (document.all) { 
  addToBookMark(window.location.href, document.title); 
  } else if (window.sidebar) { 
  addToBookMark(document.title, window.location.href); 
  } 
} 
 
function addToBookMark(url,title){ 
 var ua = navigator.userAgent.toLowerCase(); 
 if(ua.indexOf("msie 8")>-1){ 
  external.AddToFavoritesBar(url,title);//IE8 
 }else{ 
 try { 
  window.external.addFavorite(url, title); 
 } catch(e) { 
   try { 
      window.sidebar.addPanel(title, url);//firefox 
     } catch(e) { 
      alert("加入收藏失败,请使用Ctrl+D进行添加"); 
     } 
   } 
 } 
 return false; 
 
   
} 
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template