|
-
Mar 21st, 2007, 04:57 PM
#1
Thread Starter
Fanatic Member
[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!
-
Mar 21st, 2007, 05:24 PM
#2
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.
-
Mar 21st, 2007, 06:04 PM
#3
Thread Starter
Fanatic Member
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?
-
Mar 21st, 2007, 06:09 PM
#4
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.
-
Mar 21st, 2007, 06:13 PM
#5
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.
-
Mar 23rd, 2007, 10:20 AM
#6
Re: [2005] How to make a "Add to favorites" link?
 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>");
-
Mar 26th, 2007, 04:01 PM
#7
Thread Starter
Fanatic Member
Re: [2005] How to make a "Add to favorites" link?
Thank you!
Do you also know how to make a "Set as homepage" page?
-
Mar 27th, 2007, 08:25 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|