Help ; Javascript for "Bookmark"

Discussion in 'JavaScript' started by Nystul, Feb 26, 2006.

  1. #1
    Hi, I am encountering some problems with this javascript, can someone please help me take a look at it, and see why won't it function as intended? Did i mess up something?

    <script language="JavaScript" type="Text/Javascript">

    var urlAddress = "http://xxx.xxx.xxx/";
    var pageName = "xxx";

    function addToFavorites()
    {
    if (window.external)
    {
    window.external.AddFavorite(urlAddress,pageName)
    }
    else
    {
    alert("Sorry! Your browser doesn't support this function.");
    }
    }

    </script>


    ** in body i got this

    <a href="javascript:addToFavorites()"><font color="#7B1421">Bookmark Us</font></a>



    ** thanks.
     
    Nystul, Feb 26, 2006 IP
  2. amanoffewwords

    amanoffewwords Peon

    Messages:
    71
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't know, but this is what I use:

    <SCRIPT LANGUAGE="javascript">
    
    //This code is for IE v4 or better
    
    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0")
    
    {document.write("<SPAN style='cursor:hand;' onClick='window.external.AddFavorite(location.href, document.title);'>Add to favorites</SPAN></strong>")}
    
    //This code posts text if not
    
    else 
    
    {document.write("Hit CTRL-D to bookmark this page")}
    
    </SCRIPT>
    Code (markup):
    hth,
    amofw
     
    amanoffewwords, Feb 26, 2006 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    You didn't specify what your problems are, but here is working code;
    
    <script type="text/javascript">
    
    function bookmark(url, label) {
       if(window.external) {
          external.AddFavorite(url, label);
       }
       else {
          alert("you have a DOM compliant browser" + 
             "\nthat doesn't run proprietary JScript.");
       }
    }
    </script>
    ===========
    <a href="#" 
        onclick="bookmark(this.href, 'title for the page'); return false;"> bookmark</a>
    Code (markup):
    cheers,

    gary
     
    kk5st, Feb 26, 2006 IP
  4. advancescripts

    advancescripts Peon

    Messages:
    270
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it's good.

    you can use the CTR+D insted of "Sorry! Your browser doesn't support this function"
    firefox and mozila use the same
     
    advancescripts, Mar 3, 2006 IP
  5. Nathan Malone

    Nathan Malone Well-Known Member

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Try this, it should work in IE, FireFox, and Opera:

    
    <a href="" rel="sidebar" onclick="if(document.all && !window.opera){ window.external.AddFavorite(location.href, document.title);
    return false; }else{ this.title = document.title; }">Add to Favorites</a>
    
    Code (markup):
     
    Nathan Malone, Mar 3, 2006 IP
    onlinedude likes this.