Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 807
Michiel Avatar asked Sep 20 '08 11:09

Michiel


2 Answers

For Firefox no need to set any JavaScript for the bookmark an page by script, only an anchor tag with title and rel="sidebar" can do this functionality

<a href="http://www.google.com" title="Google" rel="sidebar">Bookmark This Page</a>

I have tested it on FF9 and its working fine.

When you click on the link, Firefox will open an dialog box New Bookmark and if you wish to not load this bookmark on side bar then un-check Load this bookmark in the sidebar from dialog box.

like image 142
Atul Kushwah Avatar answered Sep 26 '22 23:09

Atul Kushwah


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>
like image 30
iBobo Avatar answered Sep 25 '22 23:09

iBobo