I use the code I found at this link: link
The example uses jQuery
. I have tested again now that I am 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><buttonid="addFavorito">Adicionar Favorito</button>