Results 1 to 4 of 4

Thread: Make favorites javascript dynamic?

  1. #1
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Make favorites javascript dynamic?

    1) Script Title: Bookmark site script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex9/addbook.htm

    3) Describe problem: Not exactly a problem; more like a desired capability.

    What I'd like to be able to use is this bookmark script, but modified so that it grabs the page title and url automatically from each page it is on.

    I use php to generate the html pages in my website, reading from one php include file; what would be great is if this bookmark script could grab the page url and title from the page it is on when it is clicked. That way, the script can be included without hardcoding of the title and url for each page.

    Can javascript read page title and url's? Is this possible?

    I figured out how to include the url in the javascript function with php, but it is complicated to get a file with php and parse the title info.

    Any ideas will be good - I'm just learning coding...

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You already received your answer:

    http://www.dynamicdrive.com/forums/s...ad.php?t=18067

    But, the page must be live. Just in case there was another error in that thread, here is my (slightly less sloppy) version of the same thing - Remember only Opera will add a local bookmark with these scripts, FF and IE require a live page:

    Demo

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Test Bookmark</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    /***********************************************
    * Bookmark site script-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    /* Modified to support Opera */
    function bookmarksite(){
    var title=document.title, url=window.location.href;
    if (window.sidebar) // firefox
    	window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
    	var elem = document.createElement('a');
    	elem.setAttribute('href',url);
    	elem.setAttribute('title',title);
    	elem.setAttribute('rel','sidebar');
    	elem.click();
    } 
    else if(document.all)// ie
    	window.external.AddFavorite(url, title);
    }
    </script>
    </head>
    <body>
    <a href="javascript:bookmarksite()">Bookmark this site!</a>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks!

    Yes, trying the test page as a simple html document was the problem. The script works fine on my webserver or locally under apache and OSX.

    Now I'm searching for a way to support Safari with the script. What I've found are (I think) the functions for the bookmark dialogue for Safari:

    url=encodeURIComponent(d.location.href);
    title=encodeURIComponent(d.title);

    and I think I'll be back for more help after I try to get this to work in another else/if statement....

    Thanks!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I seriously doubt that those commands, in and of themselves, will create a bookmark in any browser. But, I could be wrong. Before we go figuring out a test as to when to use them, make sure they work in Safari at all first.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •