Scripting an add bookmark link in Firefox

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2006
Posts: 2
Reputation: kincaid is an unknown quantity at this point 
Solved Threads: 0
kincaid kincaid is offline Offline
Newbie Poster

Scripting an add bookmark link in Firefox

 
0
  #1
May 9th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Scripting an add bookmark link in Firefox

 
0
  #2
May 9th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 2
Reputation: kincaid is an unknown quantity at this point 
Solved Threads: 0
kincaid kincaid is offline Offline
Newbie Poster

Re: Scripting an add bookmark link in Firefox

 
0
  #3
May 10th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 49
Reputation: felgall is an unknown quantity at this point 
Solved Threads: 1
felgall felgall is offline Offline
Light Poster

Re: Scripting an add bookmark link in Firefox

 
0
  #4
May 11th, 2006
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).
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: pure&simpleweb is an unknown quantity at this point 
Solved Threads: 0
pure&simpleweb pure&simpleweb is offline Offline
Newbie Poster
 
0
  #5
Oct 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC