Dear experts,
This JavaScript gives an error in InternetExplorer6 (sometimes) but works perfectly in Firefox3.
<script type="text/javascript">
<!--
// Create Book Mark - CBM()
function CBM() {
var title = "domain.com";
// Blogger - Replace with <$BlogItemTitle$>
// MovableType - Replace with <$MTEntryTitle$>
var url = "
http://domain.com";
// Blogger - Replace with <$BlogItemPermalinkURL$>
// MovableType - Replace with <$MTEntryPermalink$>
// WordPress - <?php bloginfo('url'); ?>
if ( window.sidebar ) { // Mozilla Firefox Bookmark <===== error #2 here
window.sidebar.addPanel( title, url, "" ); <===== error #1 here
}
else if( window.external ) { // IE Favorite
window.external.AddFavorit
e( url, title );
}
else if( window.opera && window.print ) { // Opera Hotlist
return true;
}
} // END: CBM()
document.write( '<a href="javascript:CBM()">Bo
okmark</a>
' );
//
//-->
</script>
Error #1 is "Microsoft JScript runtime error: object doesn't support this property or method".
This error only happens on certain pages and not on others. But the pages are structured exactly the same, from the <!DOCTYPE html declaration at the top to the place where the script occurs. The script is part of a nav bar at the top of the page, which is identical in all pages of the website. The pages where the error occurs do have different content from the pages where it doesn't occur, but the different content happens after the identical top-of-page content.
Note that the script works perfectly well on Firefox3 on ALL the pages where IE6 breaks.
I tried doing:
if ( window.sidebar.addPanel )
but then I get error #2 in IE6:
Error #2 is: "window.sidebar.addPanel is null or not an object" -- AND now IE6 breaks on the pages where it worked before, and it works on the pages where it broke before -- AND the script continues to work perfectly well in FF3 !!!
How do I modify this script to get around these IE6 issues?
Or is there a better way to detect browser capabilities (caps) and launch the appropriate bookmark method for the current browser caps?
I don't want to detect browsers -- that's a losing game.
Thanks.
Start Free Trial