iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
May 14, 2008
Web Editor Reviews - 6 New Reviews
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

Using javascript to add to favourites 

  Views:    11951
  Votes:    12
by Jack Carr 12/14/03 Rating: 

Synopsis:

Here you will learn how to use a simple function so that users can ad your page to their favourites in one click.
Pages: 
The Article

How it works
First of all, we get the title of the current page, and the URL of the current page,
using JavaScript - we then pass this into a Javascript function, which pops up a box
to the user asking them to confirm whether they want to add the page to their bookmarks.

The function

This is how the function looks, we pass 2 parameters into it, and it then uses

window.external.AddFavorite

to add this page to bookmarks, as seen below:

function AddToBookmarks (url,title)
{
window.external.AddFavorite(url,title);
}
 
 

As you can see, the url and title will be passed into the function and then added
to the bookmark/favorite list of the user.

Passing the values

We use the window.title, and self.location.href objects to execute this function so that regardless of what page you put it on,
you won't need to change the values, as shown

< a href= " javascript : AddToBookmarks (self.location.href,window.title) " >Add to bookmarks</ a > 

And that's all you need to do! Simply put the javascript into some <script> tags in the <head> of the page, then put the link anywhere else!

Example:

<html>
<head>
<script>
function AddToBookmarks (url,title) { window.external.AddFavorite(url,title); }
</script>
</head>
<body>
<a href="javascript:AddToBookmarks(self.location.href,window.title)">Add to bookmarks</a >
</body>
</html>

 

And you're done, I hope you learned something new and had fun.

Pages: 

Similar/related articles:


 
  Sponsors