Bookmark using javascript

I want to bookmark my web page using javascript code. I need some javascript code to create a bookmark that should open in a new window.

I am using firefox.

+1


source to share


4 answers


Use this function:



function bookmark_us(url, title){
if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}

      

+2


source


Firefox currently has no way to do this (and there are bugs reported in bugzilla tracking this defect)



"Without being able to do this" I mean you can use the Dreas feature, but you will be limited to adding a bookmark, which will be in the sidebar by default. The end user will have to manually disable the "open in sidebar" option.

+1


source


Ask one of the Mozilla User Groups (possibly mozilla.dev.tech.xul or mozilla.dev.tech.xpcom ). You could create the correct XPCOM object to access the browser's bookmark manager - this requires permissions (the user will have to explicitly confirm this). Not portable to other browsers (obviously) and maybe not a good way to do it.

Most of the websites I've seen that make it easy to create bookmarks ( Jexe Ruderman bookmarkmark page is a great example), just ask the user to drag and drop the corresponding bookmarks into the bookmark folder of their choice and it seems much easier or simpler than trying to automatically add something to bookmark.

0


source


function bookmark_us(url, title){
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    } else if (document.all) // ie
        window.external.AddFavorite(url, title);
}

      

When used with:

<a href="#" onclick="bookmark_us('http://www.yahoo.com/', 'Yahoo!');return false;">Bookmark Us</a>

      

The above feature no longer works in Opera 9.x. He just goes to www.yahoo.com.


To create a link that opens the Add Bookmark dialog in Opera 9.x, use the following:

function bookmark_us(url, title) {
    if (window.sidebar && window.sidebar.addPanel) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.external && 'undefined' != typeof window.external.AddFavorite) // ie
        window.external.AddFavorite(url, title);
}

<a href="http://www.yahoo.com/" rel="sidebar" title="Yahoo!" onclick="bookmark_us(this.href, this.title);return false;">Bookmark Us</a>

      

0


source







All Articles