Forum Moderators: open
A legacy project had an inline "bookmarking" script (I know, I know . . . .) I initially removed the code from the page and put it in an external file, like so:
var bookmark = getBookmark('full_url_to_page','Page Title For the Bookmark');
if (bookmark) { document.write(bookmark); }
where getBookmark is the standard IE/Moz switch:
function getBookmark(url,who) {
var ver = navigator.appName;
var num = parseInt(navigator.appVersion);
var msg;
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
msg = '<a href="#" onClick="window.external.AddFavorite('+url+','+who+')'+
' return false;">Bookmark<\/a>';
}
else { msg = '<strong>Bookmark \- (Ctrl+D)</strong>'; }
return msg;
}
IE choked on it, but not on the function - on this line:
var bookmark = getBookmark('full_url_to_page','Page Title For the Bookmark');
Says ") expected."
I've since put it back inline, and it works fine. It doesn't error if I do this,
var bookmark = getBookmark('full_url_to_page');
But that's also worthless. Escaping special characters in the parameters don't have any effect.
What's the problem here?
function getBookmark (url,who) {
}
It still errors on this line in the HTML
var bookmark = getBookmark('full_url_to_page','Page Title For the Bookmark');
I've played with escaping values in the parameters, blanked them out, for whatever reason, it seems to be the two parameters causing an error in IE.
function getBookmark(url,who) {
var ver = navigator.appName;
var num = parseInt(navigator.appVersion);
var msg;
if ((ver == "Microsoft Internet Explorer") && (num >= 4)) {
msg = "<a href='#' onClick='window.external.AddFavorite(\"" + url + "\",\"" + who + "\");return false;'>Bookmark<\/a>";
}
else { msg = '<strong>Bookmark \- (Ctrl+D)</strong>'; }
return msg;
}
var bookmark = getBookmark('full_url_to_page','Page Title For the Bookmark');
if (bookmark) {
document.write( bookmark );
}