Search code examples
javascriptfirefoxbookmarks

A Firefox javascript bookmarking problem


I'm using the following JavaScript code:

<script language="JavaScript1.2" type="text/javascript">
 function CreateBookmarkLink(title, url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) {
        window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) {
        return true; }
 }
</script>

This will create a bookmark for Firefox and IE. But the link for Firefox will show up in the sidepanel of the browser, instead of being displayed in the main screen. I personally find this very annoying and am looking for a better solution. It is of course possible to edit the bookmark manually to have it not show up in the side panel, but that requires extra steps. I just want to be able to have people bookmark a page (that has a lot of GET information in the URL which is used to build a certain scheme) the easy way.

I'm afraid that it might not be possible to have Firefox present the page in the main screen at all (as Googling this subject resulted in practically nothing worth using), but I might have missed something. If anyone has an idea if this is possible, or if there's a workaround, I'd love to hear about it.


Solution

  • I think that's the only solution for Firefox... I have a better function for that action, it works even for Opera and shows a message for other "unsupported" browsers.

    <script type="text/javascript">
    function addBookmark(url,name){
        if(window.sidebar && window.sidebar.addPanel) {
            window.sidebar.addPanel(name,url,''); //obsolete from FF 23.
    } else if(window.opera && window.print) { 
            var e=document.createElement('a');
            e.setAttribute('href',url);
            e.setAttribute('title',name);
            e.setAttribute('rel','sidebar');
            e.click();
    } else if(window.external) {
            try {
                window.external.AddFavorite(url,name);
            }
            catch(e){}
    }
    else
            alert("To add our website to your bookmarks use CTRL+D on Windows and Linux and Command+D on the Mac.");
    }
    </script>