dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: adding a bookmark using JS

  1. #1
    Join Date
    Jul 2006
    Posts
    128

    adding a bookmark using JS

    i have written the following code to generate a bookmark for the current page:
    Code:
    function errorMsg()
    {
      alert("Your browser does not support this feature");
    }
    function addBookmark()
    {
      var urlValue = "http://www.trackerurl.com?url="+escape(window.location); 
      var titleValue = window.name;
      if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) { 
    	window.sidebar.addPanel(titleValue, urlValue,"");
      } else if ((typeof window.external == "object") && (typeof window.external.AddFavorite == "function")) { 
    	window.external.AddFavorite(urlValue, titleValue); 
      } else {
        errorMsg();
      }
    }
    my problem has three parts:
    1. The "titleValue = window.name;" does not seem to work correctly (what is the code to get the title of the current page?)
    2. "(typeof window.external == "object") && (typeof window.external.AddFavorite == "function")" does not seem to work in IE which is what it is aimed at...if i use "if (window.external) it works fine...why?
    3. Are there any other main browsers that I am not targeting with this code, and what should I do to add them?

    thanks

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    1) document.title is probably what you want.
    2) I've wondered that myself.
    3) Yes. Check out The Ultimate Add Bookmark Script.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  4. #4
    Join Date
    Jul 2006
    Posts
    128
    @kravvitz
    The Ultimate Add Bookmark script seems little complex to me, since I'm not used to javascript...I like coding I can understand so I can play around with it if need be....
    but regarding the site "http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html" posted by Fang....
    how does this code work in Opera:
    else if(window.opera && window.print) { // Opera Hotlist
    return true; }

    I mean, as far as I can see, it is just returning true, so its not really doing anything...I haven't tested it, but even if it worked, I'd like to know HOW...
    thnx

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Works in IE, FF and Opera:
    Code:
    <a href="#" rel="sidebar" onclick="if(document.all && !window.opera){ window.external.AddFavorite(location.href, document.title);return false; }else{ this.title = document.title; }" title="bookmark this page">Bookmark This Page</a>
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles