Question :
The code below is working, but the technique is old and probably outdated vis-à-vis the current versions of browsers:
function addFavorite( a, b ) {
title = document.title;
url = document.location;
try {
// Internet Explorer
window.external.AddFavorite( url, title );
}
catch (e) {
try {
// Mozilla
window.sidebar.addPanel( title, url, "" );
}
catch (e) {
// Opera
if( typeof( opera ) == "object" ) {
a.rel = "sidebar";
a.title = title;
a.url = url;
return true;
}
else {
// Unknown
alert( b );
}
}
}
return false;
}
Usage:
<a href="#" title="" onclick="addFavorite(this, 'Pressione Ctrl-D para adicionar a página aos seus favoritos');return false;">
Adicionar aos favoritos
</a>
Question
Is the process in its current form working efficiently or can it be simplified and updated to match the specifications of the current browser versions?
Answer :
Virtually every function you use still works, but it does not work in all browsers and there is no solution to this, for example Chromium browsers (Google Chrome, Opera, Comodo Dragon, etc.) block javascript access to this method.
You can still use it, and it will work on a portion of browsers, but it is likely that these functions will actually be “disabled” (discontinued).
The probable disuse of these methods, the idea is to make the user himself decide whether or not to add the page to favorites.
Discontinued Methods
-
window.external.AddFavorite
has been discontinued since Internet Explorer 10Source: link
-
window.sidebar.addPanel
is obsolete since Gecko 23 (Firefox technology and SeaMonkey)Note that
window.sidebar.addSearchEngine
has not been discontinuedSource: link
Apparently the only one that rel="sidebar"
was the only one not discontinued, the reason is that works differently than other methods , as