Forum Moderators: open

Message Too Old, No Replies

Cross-browser bookmark/add to favorites

can this be done as a mod to my about.com script?

         

Benek

9:43 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



I'm a designer with very little JS knowledge. I'm trying to make a bookmark this page link that works cross browser. I found a script that I like:


// Bookmark this page
// copyright 12th February, 2005
// Stephen Chapman, [javascript.about.com...]
// You have permission to copy and use this javascript provided that
// the copyright notice is included with the script

var chr = 'CTRL-D';
var agt=navigator.userAgent.toLowerCase();
if(agt.indexOf("opera")!= -1) chr = 'CTRL-T';
if (window.external)
document.write('<a href="javascript:window.external.AddFavorite(self.location,document.title)">Add to Favorites<\/a>');
else
document.write('Press '+chr+' to bookmark this page.');

with this in the html:


<script type="text/javascript" src="favlink.js">
</script>

I like this better than others I found because it replaces the link with text saying "Press CRL+D to bookmark this page." if users are not using IE.

AND, it detects the current page URL and title, rather than me having to specify it for each link.

Now I got to thinking couldn't this be cross-browser compatible?

I don't know JS, but looking at other code I found I modified the script to be:


// Bookmark this page
// copyright 12th February, 2005
// Stephen Chapman, [javascript.about.com...]
// You have permission to copy and use this javascript provided that
// the copyright notice is included with the script

var chr = 'CTRL-D';
var agt=navigator.userAgent.toLowerCase();
if(agt.indexOf("opera")!= -1) chr = 'CTRL-T';
if (window.external)
document.write('<a href="javascript:window.external.AddFavorite(self.location,document.title)">Bookmark this page<\/a>');
else if (window.sidebar)
document.write('<a href="javascript:window.sidebar.addPanel(self.location,document.title,\'\')">Bookmark this page<\/a>');

else
document.write('Press '+chr+' to bookmark this page.');

You'll see there's a part added in there that I thought would do it for Netscape/Moz, but it doesnt work. With this code IE is fine, but in Moz I get this error:


Error: [Exception... "'Script attempted to add sidebar panel from illegal source' when calling method: [nsISidebar::addPanel]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: javascript:window.sidebar.addPanel(self.location,document.title,'') :: <TOP_LEVEL> :: line 1" data: no]
Source File: javascript:window.sidebar.addPanel(self.location,document.title,'')
Line: 1

Is there a way to get this script to work how I want it to? Any help would be greatly appreciated!

DrDoc

7:36 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To my knowledge it is not possible to acheive this, as not all browsers support scripting access to the bookmarks.

Benek

8:52 pm on Jan 21, 2006 (gmt 0)

10+ Year Member



This script here works for me in FireFox, so it is possible.

[dynamicdrive.com...]

However I don't want to use that one. I was hoping I could adapt the first script to have the cross-browser functionality of this one.

Looks like it can be done, I just don't know enough JS to do it without help.

DrDoc

10:43 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It does, however, not work in Opera ... so it is not a cross-browser script. Also, I don't know how Mac browsers handle these things, and what the support is like.

Benek

11:00 pm on Jan 21, 2006 (gmt 0)

10+ Year Member



I realize that it doesn't work in opera, and likely not for any mac browser. I just figured that at least Netscape/Moz would be better than just IE. The good thing about the script that I found it that it replaces the Bookmark link with other text when it detects a non IE browser.

So my questions still remains, is it possible to modify this script so that it works with Netscape/Moz in addition to IE. I realize that this is not full cross-browser compatibility, but it's better than just IE.

Benek

5:45 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



Anyone... please?

I really have a feeling this is possbile. I just need someone to help me over the hump.