Results 1 to 8 of 8

Thread: [2005] How to make a "Add to favorites" link?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question [2005] How to make a "Add to favorites" link?

    Hello!

    How do I make a button or link that add my url to the users' favorites?

    Thanks!

    Dekel C.

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: [2005] How to make a "Add to favorites" link?

    Hello Dekelc,

    You have to use JavaScript.

    Code:
    window.external.AddFavorite(location.href, document.title);
    If you use it on a link, don't forget to return false, so the link doesn't get triggered and the page reloaded.

    HTH,
    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: [2005] How to make a "Add to favorites" link?

    thank you HoraShadow!
    do you happen to know how can I execute javascript from the code behind?

    Dekel C.

  4. #4
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: [2005] How to make a "Add to favorites" link?

    Hello Dekelc,

    No you can't. Javascript cannot be executed in the code behind because it's a client side scripting language, which means, it gets executed only on the client. On the other hand, code behind runs on the server where you are hosting the web application.

    In this context, you are trying to add the favorite in the user's browser. It's an action that has to be performed in the client itself, thus, the need of JavaScript.

    Hope that clarifies the difference between server side and client side code.
    HoraShadow
    Last edited by HoraShadow; Mar 21st, 2007 at 06:19 PM.
    I do like the reward system. If you find that my post was useful, rate it.

  5. #5
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: [2005] How to make a "Add to favorites" link?

    Following on the JavaScript code, the example I gave you on my first post only works in IE apparently.

    I did a bit of research and found this code that adds the favorite in IE and Firefox browsers.

    Code:
    function AddToFavorites() {
        if ( window.sidebar ) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url,"");
        } else if ( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title); 
        } else { // different browser
            return false; 
        }
    }
    HTH,
    HoraShadow
    I do like the reward system. If you find that my post was useful, rate it.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] How to make a "Add to favorites" link?

    Quote Originally Posted by dekelc
    thank you HoraShadow!
    do you happen to know how can I execute javascript from the code behind?

    Code:
    Page.RegisterStartupScript("FavScript","<script language='JavaScript'>window.external.AddFavorite(location.href, document.title);</script>");

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: [2005] How to make a "Add to favorites" link?

    Thank you!

    Do you also know how to make a "Set as homepage" page?
    Dekel C.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] How to make a "Add to favorites" link?

    I know of one but it works in Internet Explorer only.

    Code:
    this.style.behavior = 'url(#default#homepage)'; 
    this.setHomePage('http://www.mendhak.com/);
    As a bit of advice on the side though, this is a really 90s concept... a lot of the newer websites don't do such things.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width