Add to Favorites with JavaScript in Opera

How to make this work in Opera? I found this piece of code for Opera, but it does not work for me:

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; } } 

Dragonfly Error Console does not work, no errors.

+4
source share
4 answers

If you insist on it, do it without dynamically generated redundant links:

  <a href="http://real.url.example.com" title="Bookmark me, pleaeease!" rel="sidebar" onclick="return !addToFav(this.href,this.title)"> 

but please just don't do it.

As an Opera user, I will be grateful for not pushing this quirk - I can easily drag a tab to the bookmarks bar / panel / acceleration if I want.

+6
source

Opera applies the same user event requirement to enable bookmarking, so the code you have will not work because the user never clicked on the link you just created.

You need something more:

 function AddToFavorites(obj, 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 obj.setAttribute('href',url); obj.setAttribute('title',title); obj.setAttribute('rel','sidebar'); obj.click(); return false; } } 

Call with

 <a href="#" onclick="AddToFavorites(this, 'your title', 'your url');">Bookmark This Page</a> 

(feel free to make it more unobtrusive, I just wanted to specify a user-event requirement)

+3
source

How to get the Add to Favorites link in Opera 10 - dynamically add the rel attribute to the link

 $('#add_to_favs').attr('rel','sidebar'); 
+1
source

The following code works in Opera 8.54. It does not work in 9.27 or 9.63 (only two other versions that I have available for testing). At 9.27 and 9.63, it just transfers you to Yahoo !:

 var url = 'http://www.yahoo.com/'; var title = 'Yahoo!'; var elem = document.createElement('a'); elem.setAttribute('href', url); elem.setAttribute('title', title); elem.setAttribute('rel', 'sidebar'); elem.click(); 

I suspect that they removed the ability to add bookmarks / favorites without user initiation. Since you can already force the browser to navigate to the new URL using window.location , which is probably not considered a DoS vulnerability.

The following works fine if the user clicks on the link:

 var url = 'http://www.yahoo.com/'; var title = 'Yahoo!'; var elem = document.createElement('a'); elem.setAttribute('href', url); elem.setAttribute('title', title); elem.setAttribute('rel', 'sidebar'); elem.appendChild(document.createTextNode('Add Bookmark')); document.getElementsByTagName('body')[0].appendChild(elem); 

In addition, window.external.AddFavorite(url, title); it no longer allows the addition of non-user-selected favorites to Internet Explorer 8 Beta 2. However, if you enable it as an onclick link event, it works fine:

 <a href="http://www.yahoo.com/" title="Yahoo!" onclick="window.external.AddFavorite(this.href, this.title);return false;">Add to Favorites</a> 

Both Firefox 2.0.0.18 and 3.0.4 currently support the addition of Bookmark, which is different from the user, but I would not be surprised to see that they will delete it in a future version.

I find this to be considered poor form and a little rude in order to get a website visitor to add Favorites / bookmarks without clicking on the link or taking an explicit action that would do so. Just visiting a website is not sufficient reason to try to get these visitors to add Favorites / bookmarks to it.

0
source

All Articles