2012-08-09 68 views
0

我正在研究mvc .net應用程序,我正在使用jsgant來顯示甘特圖。我用一個xml文件從數據庫中提取數據。問題是,當我使用Chrome作爲一個航海家它不會顯示在圖表但是Firefox和IE使用正常甘特圖不適用於鉻

下面是代碼讀取XML文件(默認代碼)

JSGantt.parseXML = function(ThisFile,pGanttVar){ 
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('Chrome') > -1; // Is this Chrome 

    try { //Internet Explorer 
     xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 
     } 
    catch(e) { 
     try { //Firefox, Mozilla, Opera, Chrome etc. 
      if (is_chrome==false) { xmlDoc=document.implementation.createDocument("","",null); } 
     } 
     catch(e) { 
      alert(e.message); 
      return; 
     } 
    } 

    if (is_chrome==false) {  // can't use xmlDoc.load in chrome at the moment 
     xmlDoc.async=false; 
     xmlDoc.load(ThisFile);  // we can use loadxml 
     JSGantt.AddXMLTask(pGanttVar) 
     xmlDoc=null;   // a little tidying 
     Task = null; 
    } 
    else { 
     JSGantt.ChromeLoadXML(ThisFile,pGanttVar); 
     ta=null; // a little tidying 
    } 
} 

不任何人有一個想法如何解決這個問題?問候

+0

如果瀏覽器是Chrome瀏覽器,那麼有一個明確的條件是什麼也不做。爲什麼,你不得不問代碼的作者 – 2012-08-10 08:22:48

回答

0
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; // Is this Chrome 
    var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1; // Is this safari 
    var is_mozila = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; // Is this mozila 
    var is_Opera = navigator.userAgent.toLowerCase().indexOf('opera') > -1; // Is this opera 

if(is_safari==true) 
{var is_chrome= is_safari;} 
else if(is_mozila==true) 
{var is_chrome= is_mozila;} 
else if(is_Opera==true) 
{var is_chrome= is_Opera;} 


try { //Internet Explorer 
     xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); 

    } 
catch(e) 
    { 
    try { 

     //Firefox, Mozilla, Opera, Chrome etc. 
     if (is_chrome==false) { xmlDoc=document.implementation.createDocument("","",null); } 
     //if (is_safari==false) { xmlDoc=document.implementation.createDocument("","",null); } 
    } 
    catch(e) { 
     alert(e.message); 
     return; 
    }  
} 

if (is_chrome==false) {  // can't use xmlDoc.load in chrome at the moment 
    xmlDoc.async=false; 
    xmlDoc.load(ThisFile);  // we can use loadxml 
    JSGantt.AddXMLTask(pGanttVar); 
    xmlDoc=null;   // a little tidying 
    Task = null; 
} 
else { 
    JSGantt.loadXML(ThisFile,pGanttVar; 
    ta=null; // a little tidying 
} 
0

我會檢查jsGanttImproved,它適用於Chrome和所有主流瀏覽器。此外,它不需要任何額外的庫,它是免費的。