Forum Moderators: open
// 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 scriptvar 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 scriptvar 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!
[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.
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.