views:

2039

answers:

3

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.

A: 

You have a special case for

if (window.sidebar)

and then a branch for 'else' - wouldn't firefox land in the first branch and hence only add the panel?

Per Hornshøj-Schierbeck
What i mean is - instead of writing 'else if( window.external )' do a new if so you also get it added as a bookmark
Per Hornshøj-Schierbeck
+3  A: 

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,'');
} 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>
iBobo
you are correct. there is no way to add a page to bookmarks in firefox without it opening in a side panel.
Jan Hancic
This code in Opera just redirects the user to the link page.
Darryl Hein
A: 

Hojou,

It seems that is the only way to add a bookmark for Firefox. So FF needs to land in the first branch to have anything happening at all. I Googled some more but I'm really getting the idea this is impossible to properly address in FF...

Michiel