jamjam Posted December 2, 2010 Share Posted December 2, 2010 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 https://forums.phpfreaks.com/topic/220494-add-to-favouritesbookmarks/ Share on other sites More sharing options...
Lautarox Posted December 5, 2010 Share Posted December 5, 2010 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 https://forums.phpfreaks.com/topic/220494-add-to-favouritesbookmarks/#findComment-1143271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.