Universal add to bookmarks script?

一世执手 提交于 2019-11-29 12:04:01
Rafael

A universal script for adding to bookmarks doesn't exists, because not all browsers expose an API for creating bookmarks. Generally, only IE exposes a direct API for this. Both Opera and Firefox offer a possibility to add a site to bookmarks that will be opened in the sidebar and that is a huge difference. Safari and Chrome also don't expose any API for this task.

Some more info on this topic

I use a small script to attempt adding a bookmark using the most popular window methods, until all have failed. Then it just prompts the user to manually add their bookmark...

Like others have said (above) some browsers prohibit script-activated bookmarking, and because of security they want only users to add bookmarks.

It is not perfect, but it is simple and works well.

function addBookmark()
{
    var success=false;

    // try each until all fail...
    try {
        window.external.AddFavorite(window.location, document.title);
        success=true;
   } catch(e) {}

    try {
        window.sidebar.addPanel(document.title,location.href,'');
        success=true;
    } catch(e) {}

    if(!success)
    {
        alert("AUTO BOOKMKARING not supported\r\nIn your current browser.\r\n\r\nPress CTRL+D, or CMD+D\r\nto manually bookmark this page.");
    }
}

You can check out this jquery plugin if you are using that or just look at their source if you want to use your own. Though he mentions on his compatibility that Safari and Chrome do not expose this functionality in their API.

http://www.dummwiam.com/jFav

See digitalinspiration.

1st Google result for javascript bookmark.

In internet explorer it works with:

window.external.AddFavorite(document.location,document.title);

in firefox and in opera with:

<a href="your_link_here" rel="sidebar" title="website page title here">Some link name</a>

I haven't found a solution for safari / chrome yet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!