2013-10-29 54 views
0

請參閱以下JavaScript。這適用於除IE以外的所有其他瀏覽器。在IE Compat模式下,必須啓用它才能工作。任何想法爲什麼?我相信它與indexOf有關。Javascript只能在IE兼容模式下工作

var styles = iDoc.find("head style[id$='ReportControl_styles']").html(); 
      if ((styles == undefined) || (styles == '')) { 
       iDoc.find('head script').each(function() { 
        var cnt = $(this).html(); 
        var p1 = cnt.indexOf('ReportStyles":"'); 
        if (p1 > 0) { 
         p1 += 15; 
         var p2 = cnt.indexOf('"', p1); 
         styles = cnt.substr(p1, p2 - p1); 
        } 
       }); 
      } 
      if (styles == '') { alert("Cannot generate styles, Displaying without styles.."); } 
      styles = '<style type="text/css">' + styles + "</style>"; 
+1

請打開開發人員控制檯並查找任何錯誤。 – ComFreek

+0

使用此[鏈接](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf?redirectlocale=zh-CN&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FArray%2FindexOf )它可能對你有幫助。 – John

+0

你使用什麼IE版本? IE版本<9沒有indexOf – pax162

回答

0

目前,我已經從頁面中刪除了文檔類型,並且還添加了所有工作正常。