HTW Chur

Hochschule für Technik und Wirtschaft

IKT

Institut für Informations- und Kommunikationstechnologie

IKT Home > Team > Dozenten > Martin Studer > Using JavaScript to Add Bookmarks to Firefox

Introduction

Usually bookmarks are added manually by users, but sometimes you want to place a button on the web page that, when clicked, automatically adds a new bookmark. For example if you embed a website using iframes into another website, the user cannot add a bookmark to the embedded website. A button that adds a bookmark automatically would be useful.

 

Wrong Solution

When you browse through the net, you very often find the following Javascript code to add bookmarks to Firefox:

 

    window.sidebar.addPanel("example.org", "http://www.example.org/","");

 

This code really adds a bookmark named example.org to the bookmark folder. But when you select the bookmark, the URL is opended in the sidebar instead of in the main window.

 

Often used Javascript code adds bookmarks that open URL in the Firefox sidebar.

Try it, use the button below:

 

 

See that the property page of the bookmark has "Load this bookmark in the sidebar" checked.

 

The bookmark property page has "Load this bookmark in the sidebar" checked

Right Solution

The solution to this problem can be found in the Firefox DOM documentation. See the following links:

Or try the button below:

 

 

Ususally nothing happens when you click on the button above. This is because of the security settings in Firefox. For the button to work you have to lower the security settings or, for a production web site, you have to sign the script. See the following link:

Studer Martin Studer Martin, Prof., Dipl. Informatik-Ingenieur ETH
Leiter angewandte Forschung und Entwicklung Institut IKT, Standortleiter MSE, Leiter IKT, Professor
Telefon: +41 (0)81 286 24 43
> E-Mail
> Mehr zur Person