Ask The Trades
https://www.askthetrades.co.uk/cgi-bin/yabb/YaBB.pl
DIY Forum >> Alarms, Phones, Aerials, CCTV & Datacomms >> Favorites
https://www.askthetrades.co.uk/cgi-bin/yabb/YaBB.pl?num=1339348185

Message started by cumbriahandyman on Jun 10th, 2012, 6:09pm

Title: Favorites
Post by cumbriahandyman on Jun 10th, 2012, 6:09pm

I am looking for an html code for my website so that people can click it to put my site into their favorites folder.

I have one already but when clicked on it opens the favorites folder but had gadget in the name box. I want it to say Handyman Cumbria.

Cheers

Title: Re: Favorites
Post by Lectrician on Jun 10th, 2012, 6:25pm

These buttons are a little out of date these days as adding a favourite to your browser is quick and easy.

Drag the page to the top bar, use the menu, or simply press CTRL & D.

To add a button, you need to use some javascript.

Because there are so many browsers these days, and so many people use ones other than IE, this becomes tricky.

Let me take a look at some code it a bit, however, the name for the favorite is usually taken from the <title></title> tag you have for your website.  What was the title of your website (in the top browser bar) where you button or link was?

Title: Re: Favorites
Post by cumbriahandyman on Jun 10th, 2012, 6:36pm

Its on my home page is that what you meant?

Title: Re: Favorites
Post by Lectrician on Jun 10th, 2012, 6:53pm

Copy and paste the below into a text file and save it as fav.html or something - then give it a try.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Add To Favorites</title>
<script language="JavaScript" type="text/javascript">
function addFav(title, url) {
 if (window.sidebar){ // For Firefox
   window.sidebar.addPanel(title, url, "");
   return false;
 }
 else if( window.external ){ // For Internet Explorer & Safari
   window.external.AddFavorite(url, title);
   return false;
 }
 else if(window.opera && window.print){ // For Opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
    return false;
 }
}
</script>
</head>
<body>
<input type="button" value="Bookmark Us!" onclick="addFav('My Title Here', 'http://myURLlink.com');"><p>
Or - do you want a text link?<p>
<a href="javascript:void(0);" onclick="addFav('My Title Here', 'http://myURLlink.com');">Bookmark Us!</a><p>
Incidently - Google Chrome does not allow javasctipt to add a bookmark (it's version of a favorite).
</body>
</html>

Title: Re: Favorites
Post by Lectrician on Jun 10th, 2012, 6:57pm


wrote on Jun 10th, 2012, 6:36pm:
Its on my home page is that what you meant?


Looking at your code, it is from a creator type site, and is using the javascript variable "document.title" which should pull your websites title in as the favorite name (could also try this.title).  The title you have is simply "Home" though.  You should have the website set as your title.

The code I have done above doesn't use these variables and you can set them as you wish.

You should have in your head of the webpage <title>My Website Name - Home</title> rather than just <title>Home</title>

You can also put after your "If this button doesn't work, add us manually" text, "press CTRL & D!"

Title: Re: Favorites
Post by cumbriahandyman on Jun 10th, 2012, 7:20pm

Cheers for that the code would not work on my site but I have added the ctrl + D. I think I will leave it at that.

I do appreciate you putting in the time to help.

John

Title: Re: Favorites
Post by Lectrician on Jun 10th, 2012, 7:23pm

You would need to put everything in the <script> tags (with the script tags still) inside your <head> tag - usually after the <title> tag.

Then the HTML button where ever you want.

Did you copy and paste the code above into a clean page and tried that?

Send me the file if you want.

Ask The Trades » Powered by YaBB 2.3!
YaBB © 2000-2008. All Rights Reserved.