0

I'm implementing a bookmark feature in a web application. Works fine in FF (Chrome does not support it), but it throws an error in IE8 and does not even work in IE9 & IE10.

This is the code (it's inside a click handler function, so pretty straight forward):

if(window.sidebar) {
    window.sidebar.addPanel("EXOP - GRD", $(this).data('href'), "");
} else if(window.external && window.external.AddFavorite) {
    window.external.AddFavorite($(this).data('href'), "EXOP - GRD");
} else if(window.opera) {
    $(this).attr({
        href:$(this).data('href'),
        title:"EXOP - GRD",
        rel:"sidebar"
    })
} else {
    console.log("Bookmark Action not supported");
    return false;
}

But IE8 breaks on line 3 pointing to the if with the error Object doesnt support This Property or Method. What???

Also this stuff should work in IE9 & 10, shouldn't it?

Any help would be really appreciated.

Johannes Klauß
  • 10,676
  • 16
  • 68
  • 122

1 Answers1

1

It's not working on browsers other than Firefox because it's firefox-specific.

From the Mozilla documentation for window.sidebar:

Specification - "Mozilla-specific. Not part of any standard."

The solution? one way is to determine which browser is being used, and separate the code accordingly.

The reason is that each part of your code will 'break' when run in it's not-native browser (as the objects do not exist outside their native browser - for example in IE, it will never make it to your else if {} because of the Firefox-specific object in the first part of the if {} breaking it, hence your error message).

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • I know. The first `if` is for Mozilla, second for IE, third for Opera and the `else` is to log, that this feature is not supported. – Johannes Klauß May 17 '13 at 08:29
  • @JohannesKlauß Is there no way of you changing your `if {}` statement so that the Mozilla part falls into the `else {}`, so that you don't have to mention `window.sidebar`? Or determining if IE8 is being used, and skipping over the statement? – dsgriffin May 17 '13 at 08:32
  • Well, I already tried, but the error still occurs, pointing to the `if` before `window.external && window.external.AddFavorite`, that the Object doesn't support this property or method. – Johannes Klauß May 17 '13 at 08:35
  • @JohannesKlauß Just determine which browser is being run and run the appropriate part inside that. I know it's frustrating, but each part will break in different browsers as the conditions don't exist outside of their native browser.. – dsgriffin May 17 '13 at 08:36
  • @JohannesKlauß Yeah. the fun of browser compatibility huh? – dsgriffin May 17 '13 at 14:28