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.