SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    "bookmark us" script?

    Hey all. Does anyone know any good cross-browser script
    that will add the page to the person's bookmarks?

    tia,
    --ed

  2. #2
    ********* Shroom mydster's Avatar
    Join Date
    Nov 2002
    Location
    tpyge
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <a href="javascript:window.external.AddFavorite('URL','Name')">add to Favorites</a>

  3. #3
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by mydster
    <a href="javascript:window.external.AddFavorite('URL','Name')">add to Favorites</a>
    That's pretty much IE only though isn't it?

    --ed

  4. #4
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, it is. Afaik, it's specifically MSIE/Win (i.e. not supported by MSIE/Mac).

    Afaik, at present there is no way to offer an 'add link' kind of facility to other browsers.
    So, seeing as you're already using javascript , why not use it to offer the advice/facility that is appropriate to the browser?

    Code:
    <head>
    ...
    <script type="text/javascript">
    function doLink() {
    if ( (document.all) && (navigator.platform.indexOf('Win') != -1) ) {
    document.write("<a href='#' onclick='window.external.AddFavorite('URL','Name')'>Add this page to Favorites</a>");
    } else {
    document.write("Press Control+D to bookmark this page (Command+D for Macintosh)");
    }
    }
    </script>
    </head>
    
    <body>
    ...
    <script type="text/javascript">doLink()</script>

    Hope that helps.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  5. #5
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I didn't know if there was a cross-browser way to do it or not.
    What I've done so far is just use php to only show the link
    if they're using IE. But now that I know that it doesn't work on
    mac either I should change this code to also check that the OS
    is Windows.

    PHP Code:
      <?php

      
    if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) 
      {
        
    ?>
        <a href="javascript:window.external.AddFavorite('http://www.mysite.com','The title of my site')" class="bottomLeftNav">Bookmark us</a>
        <?php
      
    }

      
    ?>
    Maybe change it to the following.


    PHP Code:
      <?php

      
    if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && strstr($_SERVER['HTTP_USER_AGENT'], 'Win')) 
      {
        
    ?>
        <a href="javascript:window.external.AddFavorite('http://www.mysite.com','The title of my site')" class="bottomLeftNav">Bookmark us</a>
        <?php
      
    }

      
    ?>

    thanks all,
    --ed

  6. #6
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quick question...

    Is there any benefit in using PHP (your example) rather than javascript (my example) given that the facility you are implementing is javascript-based anyway?
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  7. #7
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Bill Posters
    Quick question...

    Is there any benefit in using PHP (your example) rather than javascript (my example) given that the facility you are implementing is javascript-based anyway?
    I don't think there's any real benefit with php in this case.
    I actually came up with my quick peice of php
    last night. If I hadn't already done it I woulda just used your javascript code, as I used mydster's code to open the bookmarks window.

    The navigation that this link is a part of is an "included" php file, so it was kinda natural for me to do the logic in php. That's kind of the purpose of my having a seperate file for navigation.

    And I'm a quite a bit more comfortable with php than I am with javascript so I probably tend to use php when possible.

    So I guess it largely comes down to personal preference.

    --ed


Bookmarks

Posting Permissions

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