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.