944,026 Members | Top Members by Rank

Ad:
May 9th, 2006
0

Scripting an add bookmark link in Firefox

Expand Post »
Hello everyone - new member here!

I have a javascript function for creating an 'add bookmark' link on my pages. For firefox it uses window.sidebar.addPanel to add the bookmark

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. function addBookmark(title, url) {
  3. if (window.sidebar) { // firefox
  4. window.sidebar.addPanel(title, url,"");
  5. } else if( document.all ) { //MSIE
  6. window.external.AddFavorite( url, title);
  7. } else {
  8. alert("Sorry, your browser doesn't support this");
  9. }
  10. }
To call it I use

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. <a href="javascript:addBookmark('astro','http://www.astroman.com')>Add bookmark</a>
  3.  
The problem lies in the firefox part. A page bookmarked with this function opens in the firefox sidebar. (perhaps unsurprisingly given the name of the method).
Anyone know a way to prevent this or a function that does the job better ? windows.sidebar.addPanel is the only way I know of scripting an add bookmark link in Firefox

I'm using Firefox 1.5.0.3

Jamie
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kincaid is offline Offline
2 posts
since May 2006
May 9th, 2006
0

Re: Scripting an add bookmark link in Firefox

That's the way it is supposed to work. Actualy, USERS are supposed to add their own bookmarks; it's not something a site should be doing.

However, a web-search reveals this page as the very first result.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 10th, 2006
0

Re: Scripting an add bookmark link in Firefox

Quote originally posted by tgreer ...
That's the way it is supposed to work. Actualy, USERS are supposed to add their own bookmarks; it's not something a site should be doing.
However, a web-search reveals this page as the very first result.
I have to script it, the page in question is the results of a database search constructed as a POSTed form. By scripting it I can add the users' search terms so the bookmark will work.

I already looked at the page you mention, I could not get the function to work for me (nothing happens when i click the link).

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script>
  2. function addBookmarkForBrowser() {
  3. if (document.all)
  4. {
  5. window.external.AddFavorite(document.location.href, document.title);
  6. } else {
  7. var ea = document.createEvent("MouseEvents");
  8. ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
  9. var eb = document.getElementsByTagName("head")[0];
  10. eb.ownerDocument getter = new Function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
  11. eb.dispatchEvent(ea);
  12. }
  13. }
  14. </script>
  15.  
  16. <a href="javascript:addBookmarkForBrowser();">Add to Favorites</a>

does anyone have any idea why? does it work for you?

Jamie
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kincaid is offline Offline
2 posts
since May 2006
May 11th, 2006
0

Re: Scripting an add bookmark link in Firefox

Quote originally posted by kincaid ...
if (document.all)
{
window.external.AddFavorite(document.location.href, document.title);
That code will crash Opera which understands document.all but doesn't understand window.external

You should be testing for window.external not for document.all in the if statement since that is the feature you require to use not the one you are currently testing.

With Firefox you can add to the sidebar but not to the bookmarks. To add to bookmarks in Firefox without selecting the bookmarks menu your visitor must press CTRL-D (similarly the only way to do it in Opera is CTRL-T).
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
felgall is offline Offline
50 posts
since Aug 2004
Oct 22nd, 2009
0
Re: Scripting an add bookmark link in Firefox
Very helpful scripting codes you all have shared. Thank you!

<FAKE SIGNATURE>
Last edited by peter_budo; Oct 25th, 2009 at 5:08 am. Reason: Keep It On The Site - Do not manually post "fake" signatures in your posts.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pure&simpleweb is offline Offline
1 posts
since Oct 2009
17 Days Ago
0

Firefox Bookmark by Script

For FireFox no need to set any javascript for the bookmark, only an anchor tag with title and rel="sidebar" can do this functionality

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="http://www.google.com" title="Google" rel="sidebar">Bookmark This Page</a>

I have tested it on FF9
Reputation Points: 10
Solved Threads: 0
Newbie Poster
atul.kushwah is offline Offline
1 posts
since Jan 2012
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Trigger with link
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: New In JS and JSON





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC