I use the code I found on this link: https://www.thewebflash.com/how-to-add-a-cross-browser-add-to-favorites-bookmark-button-to-your-website/
The example uses jQuery
. I tested again now that I’m answering this question to confirm compatibility, and it works on IE
11, Firefox
51 and Chrome
63:
$('#addFavorito').click(function(e) {
var bookmarkURL = window.location.href;
var bookmarkTitle = document.title;
if ('addToHomescreen' in window && addToHomescreen.isCompatible) {
// Mobile browsers
addToHomescreen({ autostart: false, startDelay: 0 }).show(true);
} else if (window.sidebar && window.sidebar.addPanel) {
// Firefox <=22
window.sidebar.addPanel(bookmarkTitle, bookmarkURL, '');
} else if ((window.sidebar && /Firefox/i.test(navigator.userAgent)) || (window.opera && window.print)) {
// Firefox 23+ and Opera <=14
$(this).attr({
href: bookmarkURL,
title: bookmarkTitle,
rel: 'sidebar'
}).off(e);
return true;
} else if (window.external && ('AddFavorite' in window.external)) {
// IE Favorites
window.external.AddFavorite(bookmarkURL, bookmarkTitle);
} else {
// Other browsers (mainly WebKit & Blink - Safari, Chrome, Opera 15+)
alert('Press ' + (/Mac/i.test(navigator.userAgent) ? 'Cmd' : 'Ctrl') + '+D to bookmark this page.');
}
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="addFavorito">Adicionar Favorito</button>
Possible duplicate of Bookmark
– NoobSaibot