Forum Moderators: open

Message Too Old, No Replies

How to write a javascript link which creates a bookmark in Firefox

Yes, that old chestnut...

         

ronin

3:00 pm on Apr 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A bit late to the party, but I have just downloaded FF 2.0.0.3

I had thought that finally (finally!) I would be able to rewrite the javascript links on my site so that it would be possible for readers to bookmark a page which subsequently opens in the Firefox main window.

Yes, of course they can use CTRL+D if they know to do so, but it doesn't hurt to have an on-page option as well.

I am currently using a script which bookmarks pages for both IE and Opera. But, unfortunately, the best it can do for FireFox is to save pages to the bookmarks list... which subsequently open in the side-panel.

This is not what I want, it's not very useful (no URL bar etc.) and its almost certainly not what the novice user expects.

Am I missing something? Is there any way to script a bookmarking function for FF2? Or is this just not going to be possible until FF3 (if ever)?

birdbrain

9:51 am on Apr 9, 2007 (gmt 0)



Hi there ronin,

this will work for IE, Opera and Firefox...


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>IE, Opera and Firefox bookmark script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
li {
margin:5px 0;
}
a {
color:#000;
}
.bm {
color:#900;
}
</style>

<script type="text/javascript">

window.onload=function() {
links=document.getElementsByTagName('a');
for(c=0;c<links.length;c++) {
if(links[c].className=='bm') { /*this specifies the bookmark links by class*/
links[c].onclick=function() {
bookmarks(this.title,this.href);
}
}
}
}

function bookmarks(title,url){
if(window.sidebar) {
window.sidebar.addPanel(title,url,'');
}
else {
if((window.opera)&&(window.print)){
lnk=document.createElement('a');
lnk.setAttribute('href',url);
lnk.setAttribute('title',title);
lnk.setAttribute('rel','sidebar');
lnk.click();
}
else {
window.external.AddFavorite(url,title);
}
}
}

</script>

</head>
<body>

<ul>
<li><a class="bm" title="webmasterworld" href="http://www.webmasterworld.com/">Bookmark webmasterworld.com</a></li>
<li><a href="http://www.w3schools.com/">Do not bookmark w3schools.com</a></li>
<li><a class="bm" title="w3c.org" href="http://www.w3c.org/">Bookmark w3c.org</a></li>
</ul>

</body>
</html>

birdbrain

dreamcatcher

12:08 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[dynamicdrive.com...]

Works fine in FF2.

dc

ronin

3:34 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks birdbrain and dreamcatcher.

Both those scripts (like the one I already have) open the FF bookmark in the side-panel.

I was wondering if there is a script which allows FF bookmarks to be opened in the main viewport.