Hello!
How do I make a button or link that add my url to the users' favorites?
Thanks!
:wave:
Printable View
Hello!
How do I make a button or link that add my url to the users' favorites?
Thanks!
:wave:
Hello Dekelc,
You have to use JavaScript.
If you use it on a link, don't forget to return false, so the link doesn't get triggered and the page reloaded.Code:window.external.AddFavorite(location.href, document.title);
HTH,
HoraShadow
thank you HoraShadow!
do you happen to know how can I execute javascript from the code behind?
:wave:
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
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.
HTH,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;
}
}
HoraShadow
Quote:
Originally Posted by dekelc
Code:Page.RegisterStartupScript("FavScript","<script language='JavaScript'>window.external.AddFavorite(location.href, document.title);</script>");
Thank you!
Do you also know how to make a "Set as homepage" page?
I know of one but it works in Internet Explorer only.
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.Code:this.style.behavior = 'url(#default#homepage)';
this.setHomePage('http://www.mendhak.com/);