Advanced Search

Results 1 to 4 of 4

Thread: Placing the current URL in a bookmark

  1. #1
    Join Date
    Mar 2009
    Location
    RTP, NC
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Placing the current URL in a bookmark

    I am brand new here and to JS ~ if this is the wrong forum for this type of post I will gladly take it elsewhere!

    I would like to be able to have a user capture the page they are viewing quickly and efficiently into a bookmark. Bouncing around the net I found several different scripts where you could hardcode a bookmark - for example, a start page. What I want a user to do is something like this, navigate down to: http://www.example.com/firstpage/sec.../thirdpage.htm and let the reader place that URL into their bookmarks, by clicking on an image perhaps.

    This is my current approach (which is not working and thus why I am here). I have a Jscript dir sitting under my Code dir. In that Jscript dir I have the following script: "bookmark.js" and it contains this code:

    function addbookmark() {
    title = "document.title";
    url = "window.location.href";
    if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
    } else if( window.external ) {
    window.external.AddFavorite( url, title); }
    }
    if (window.external) {
    document.write('<a href =
    "javascript:addbookmark()");">Add to Favorites</a>');
    } else if (window.sidebar) {
    document.write('<a href =
    "javascript:addbookmark()");">Bookmark Page</a>');
    }

    In the head section of pages using this function:

    <script language="JavaScript" type="text/javascript" src="Jscript/bookmark.js"></script>

    This is the XHTML in the actual pages that use this function:

    <a href="javascript:addbookmark(document.title, window.location.href)"><img src="images/bookmark.gif" /></a>

    All of the above is pretty much cobbled together from bits and pieces I found. I don't pretend to be a programmer, nor JS literate. Any pointers you could offer me to make this work are muchly appreciated ...

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Maybe change this:

    Code:
    function addbookmark() {
    title = "document.title";
    url = "window.location.href";
    if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
    } else if( window.external ) {
    window.external.AddFavorite( url, title); }
    }
    if (window.external) {
    document.write('<a href =
    "javascript:addbookmark()");">Add to Favorites</a>');
    } else if (window.sidebar) {
    document.write('<a href =
    "javascript:addbookmark()");">Bookmark Page</a>');
    }
    to this:

    Code:
    function addbookmark() {
        title = document.title;
        url = window.location.href;
        if (window.sidebar) {
            window.sidebar.addPanel(title, url, "");
        } else if (window.external) {
            window.external.AddFavorite(url, title);
        }
    }
    if (window.external) {
        document.write('<a href="javascript:addbookmark();">Add to Favorites</a>');
    } else if (window.sidebar) {
        document.write('<a href="javascript:addbookmark();">Bookmark Page</a>');
    }

  3. #3
    Join Date
    Mar 2009
    Location
    RTP, NC
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Tried your suggestion Chris and thank you very much for your thoughts. Sadly, it did not change anything. What started me down this path is that I had some code left over from an earlier rev of the app I am building and it worked fine in FireFox, but not in IE. Thus, I went on a search for something that would work in either world.

    Does anyone have something to share that might help me out?

  4. #4
    Join Date
    Mar 2009
    Location
    in the backseat on my camel
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink i hope this one will help you

    i hope this one will help you (i've test it in IE 6, FF 3 and Opera and it works):

    1.put this on the head of your page:

    Code:
    <script type="text/javascript">
    <!--
    title = document.title;   
    url = window.location.href;
    function CreateBookmarkLink() { 
    	if( document.all ) { 
    		window.external.AddFavorite(url,title); 
    	} else if (window.sidebar) { 
    		window.sidebar.addPanel(title,url,"");	
    	} else if(window.opera && window.print) { 
    		return true;
    	} 
    }
    //-->
    </script>
    2.put this one in the body of your document:

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    	if (window.opera && window.print) {
    	document.write('<a rel="sidebar" href="' + url + '" title="' + title + '" class="favorites">Add to favorites</a>'); 
    	} else if (document.all) {
    	document.write('<a href="#" onclick="CreateBookmarkLink(); return false;" title="' + title + '" class="favorites">Add to favoritese</a>');   
    	} else  if (window.sidebar) {
    	document.write('<a href="#" onclick="CreateBookmarkLink(); return false;" title="' + title + '" class="favorites">Add to favorites</a>'); 
    	} 
    //-->
    </script>
    SOME TIPS:
    -you should not access the file directly (the adress would be like "file:///C:/Documents and Settings/..."), it won't work.
    -if you are still in doubt, checkout this adress: http://servicecalculatoare.z1.ro/

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
  •