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 (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 2, 2009
What would you think of human placed ads?
About
 
July 2, 2009
W3C Drops Audio and Video Codec Requirements From HTML 5
Hot Wired
 
July 2, 2009
Build Your Own Database Driven Web Site using PHP & MySQL - Part 1:...
SitePoint
 
July 2, 2009
Poll: Which social media sites do you use to promote your Web pages?
About
 
July 2, 2009
Bing jumps on Twitter-mania with tweet index
WebDevTips UK
 
July 2, 2009
Facebook to Offer New Features to Allow Users to Control Privacy of...
WebDevTips UK
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

Using javascript to add to favourites 

  Views:    15231
  Votes:    14
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