none
Boolean(external.AddToFavoritesBar) causes: SCRIPT438: Object doesn't support this property or method

    Question

  • Hello,

    I'm trying to implement feature-detection for programmatically adding a webslice in javascript;

    The code can be as simple as this:

     

    if (Boolean(external.AddToFavoritesBar)) {
     external.AddToFavoritesBar('link', 'title', 'slice')
    }
    

    but the check on the existence of the function AddToFavoritesBar provokes a

     

    SCRIPT438: Object doesn't support this property or method

     

    error.

    If I skip the check and just execute the AddToFavoritesBar function it works!!!!

    I'm on IE9 9.0.7930.16406

     

    Is this a bug in IE9? Could somebody do a quick test in IE8 please??

    Thanks for your help!

    Friday, January 28, 2011 10:16 AM

Answers

  • Hello again Rob,

    connect.microsoft.com  has been down all morning for me (when trying to search for a possible similar bug) but indeed this bug should be posted eventually.

    On the solution itself, this seems to work for me (IE9, chrome, firefox, safari):

    if ('AddToFavoritesBar' in external) {
      alert('supported');
    } else {
      alert('unsupported');
    }
    

    could you please give it a test on IE8 if you have it available?

    thanks!

     

    Monday, January 31, 2011 2:55 PM

All replies

  • Hi,

    Same happens in IE8.

    Workaround - use conditional comments... the method is IE specific

    or

    try{}catch(e){}

    Here is my asp.net web control...

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="ctlAddtoFavBar.ascx.vb" Inherits="Controls_ctlAddtoFavBar" %>
    <!--[if gte IE 8]>
    <a title="Add to Favorites Bar" href="#" onclick="javascript:window.external.AddToFavoritesBar('<%=sUrl %>', '<%=sTitle %>');return false;"><asp:Image runat="server" ID="cmdAdd2FavBar" AlternateText="Add to Favorites Bar" ImageUrl="Add2FavBar.gif" height="32" width="32" border="0" /></a>
    <![endif]-->
    <a title="Add to Favorites" href="#" onclick="javascript:addToBookMarks('<%=sUrl %>', '<%=sTitle %>');return false;" ><asp:Image runat="server" ID="cmdAdd2Favs" AlternateText="Add to Favorites" ImageUrl="Add2Favs.gif" height="32" width="32" border="0" /></a>
    

    and addToBookMarks js function

    function addToBookMarks(sHref, sTitle)
    {
    if(document.all)
      window.external.AddFavorite(sHref, sTitle);
    else if(window.sidebar)
      alert("Netscape, Sea Monkey and Firefox users.\nRight-Click this link/page and select \'Bookmark this link...\' from the drop-down menu.");
      //window.sidebar.addPanel(sTitle, sHref,'');
    else if(window.opera)
      alert("Opera users.\nRight-Click this link/page and select \'Bookmark this link...\' from the drop-down menu.");
    }
    
    

     

     


    Rob^_^
    Friday, January 28, 2011 6:54 PM
  • Hello Rob,

     

    thanks for you answer!

    mmh, conditional comments would work indeed (even though I do not like them much :-) )!

    simple, and I haven't thought of them, though I have to play around a little for the alternative action (same button that behaves differently), but I'm sure I can sort it out!

     

    I'll let another day and see if other ideas come in, otherwise that will be the answer!

    Friday, January 28, 2011 7:21 PM
  • By all rights we (you or I) should send feedback at connect.microsoft.com/ie for them to fix it as the first principle would be to use a feature test in the form if(external.addToFavoriteBar) and if(external.addToFavorites)

    but since it is in both IE8 and 9... the horse has already left the gate.

    Regards.


    Rob^_^
    Friday, January 28, 2011 8:53 PM
  • Hello again Rob,

    connect.microsoft.com  has been down all morning for me (when trying to search for a possible similar bug) but indeed this bug should be posted eventually.

    On the solution itself, this seems to work for me (IE9, chrome, firefox, safari):

    if ('AddToFavoritesBar' in external) {
      alert('supported');
    } else {
      alert('unsupported');
    }
    

    could you please give it a test on IE8 if you have it available?

    thanks!

     

    Monday, January 31, 2011 2:55 PM
  • hi StefanoC,

    thank you for sharing the solution.

    it was working in my end of IE8.

    thanks~


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
    Friday, February 04, 2011 9:41 AM
    Moderator