I really do not know if anybody use a favorite button on their websites. I know that social media buttons plugins are widely used and many on this plugins are also supports add to favorite button.
So, why I want to write a post about it? Because still a lot of my clients ask me to install the button on their websites.
And there is a cross-browser solution.
First of all let me show you the bookmark button HTML:
<a href="javascript:void(0)" onClick="return rudr_favorite(this);">Add to favorites</a>
The button JavaScript:
function rudr_favorite(a) { pageTitle=document.title; pageURL=document.location; try { // Internet Explorer solution eval("window.external.AddFa-vorite(pageURL, pageTitle)".replace(/-/g,'')); } catch (e) { try { // Mozilla Firefox solution window.sidebar.addPanel(pageTitle, pageURL, ""); } catch (e) { // Opera solution if (typeof(opera)=="object") { a.rel="sidebar"; a.title=pageTitle; a.url=pageURL; return true; } else { // The rest browsers (i.e Chrome, Safari) alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D to bookmark this page.'); } } } return false; }
Only the best of WordPress
Subscribe to this weekly newsletter to receive the latest blog posts by email.I respect your privacy. Your email is safe with me.
thank you bro helpd me a lot
Doesn’t work for Firefox and Opera. In all browsers I get “Press Ctrl+D to bookmark this page.”