Jump to content

Add to favourites/bookmarks


jamjam

Recommended Posts

 

Hi

 

I am complete javascrpt newbie, I have this script. Not my work.

 

function fav() { 
var newT = document.createTextNode('Add to Favourites'); 
var s = document.getElementById('fav'); 
if (window.sidebar) { 
s.appendChild(newT); 
s.style.cursor = 'pointer'; 
s.onclick = function() {window.sidebar.addPanel(document.title,self.location,'')}; 
} else if (window.external) { 
s.appendChild(newT); 
s.style.cursor = 'pointer'; 
s.onclick = function() {window.external.AddFavorite(self.location,document.title)}; 
} else if (window.opera) { 
s.appendChild(newT); 
s.style.cursor = 'pointer'; 
s.onclick = function() { 
var e = document.createElement('a'); 
e.setAttribute('href',self.location); 
e.setAttribute('title',document.title); 
e.setAttribute('rel','sidebar'); 
e.click(); 
  } 
} 
} 
var pageLoaded = 0; 
window.onload = function() {pageLoaded = 1;} 
function loaded(i,f) { 
if (document.getElementById && document.getElementById(i) != null) f(); 
else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100); 
} 
loaded('fav',fav); 

 

 

The script adds a add to favourites link to a page.

 

This works without any problems.

 

My intention is to adapt the script so instead of outputting a link(text) it outputs a image.

 

But I don't how to do this.

 

Please help. Thanks

Link to comment
Share on other sites

If you take a look to the code,

var e = document.createElement('a'); 
e.setAttribute('href',self.location); 
e.setAttribute('title',document.title); 
e.setAttribute('rel','sidebar');

It is creating an "a" element, an anchor element and giving some attributes to it, you should read about creating other elements such images and giving attributes to it, you can check http://www.w3schools.com/js/default.asp

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.