function AddToFavorites(title, url) {
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
return false;
}
else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title);
return false;
}
else if(window.opera && window.print) { // Opera Hotlist
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
return false;
}
}
window.external.AddFavorite( url, title);
- everything is simplewindow.sidebar.addPanel(title, url,"");
- also easyadd this page to bookmark
add this page to bookmark
with attribute rel = "sidebar" .alert('Pls, press Ctrl + D or CMD + D for MAC, \n to add this page to your bookmarks.');
// JS
function bookmark(a){
if (window.sidebar){ // firefox
return false;
}
else if(window.opera && window.print){ // opera
return false;
}
else if(document.all){ // ie
window.external.AddFavorite(a.href2 || a.href, a.title);
if(!a.href2){
a.href2 = a.href;
a.href="#";
}
} else {
alert('Pls, press Ctrl + D or CMD + D for MAC, \n to add this page to your bookmarks.');
a.href=+"#";
return false;
}
}
//HTML
<a href="http://yoursite/" rel="sidebar" onclick="bookmark(this)" title="My JS Bookmarks" > add this page to bookmark </a>
Source: https://habr.com/ru/post/74288/
All Articles