功能在IE8中运行良好,但在Chrome,Mozilla,safari中没有

时间:2013-08-06 12:45:34

标签: javascript jsp

我在事件onClick

上调用此函数
function openGrpLifeStmtReport (busnsourceid,treatyId,policyid,productid,schemename,periodfrom,periodto,plcyeffdtfrom,polcyeffto,benType,exportTo,jasperName,jasperNamesum,reportvar1,reportvar2,reportvar3,reportvar4,userloged,clientId)
{

    document.getElementById("reportvar1").value = document.getElementById("busnsourceid").value;
    document.getElementById("reportvar2").value = document.getElementById("treatyId").value;
    document.getElementById("reportvar4").value = document.getElementById("productid").value;
    var Busnsourceid=document.getElementById(busnsourceid).value;
    var TreatyID=document.getElementById(treatyId).value;
    var PolicyID=document.getElementById(policyid).value;
    var ProductID=document.getElementById(productid).value;
    var SchemeName=document.getElementById(schemename).value;
    var PeriodFrom=document.getElementById(periodfrom).value;
    var PeriodTo=document.getElementById(periodto).value; 
    var plcyeffdtfrom=document.getElementById(plcyeffdtfrom).value;
    var polcyeffto=document.getElementById(polcyeffto).value;
    var BenType=document.getElementById(benType).value;
    var exportTo=document.getElementById(exportTo).value;
    var jasperName=document.getElementById(jasperName).value; 
    var jasperNamesum=document.getElementById(jasperNamesum).value; 
    var userloged=document.getElementById(userloged).value;
    var clientId=document.getElementById(clientId).value;
    var reportvar3; 
    var disorderby = document.getElementById("orderBy").value;
    var disgroupby = document.getElementById("groupBy").value;
            for (var form=0; form < document.forms.length; form++) 
        {
         var what = document.forms[form];
         for (var i=0, j=what.elements.length; i<j; i++) 
         {
           if (what.reportvar3[i].checked == true) 
            {
                reportvar3 = what.reportvar3[i].value;          
                break;  
            }
         } 
        }

        var url = "./GroupLifeAdvRep.do?action=customAction&innerAction=printGrpLifeRep&CedantCode="+Busnsourceid+"&TreatyID="+TreatyID+
            "&Policy Id="+PolicyID+"&ProductID="+ProductID+"&SchemeName="+SchemeName+"&PeriodFrom="+PeriodFrom+"&PeriodTo="+PeriodTo+"&plcyeffdtfrom="+plcyeffdtfrom+"&polcyeffto="+polcyeffto+"&BenType="+BenType+"&exportTo="+exportTo+"&jasperName="+jasperName+"&jasperNamesum="+jasperNamesum+"&reportvar1="+reportvar1+"&reportvar2="+reportvar2+"&reportvar3="+reportvar3+"&reportvar4="+reportvar4+"&disorderby="+disorderby+"&disgroupby="+disgroupby+"&userloged="+userloged+"&clientId="+clientId;
        window.open(url,"target","width=850, height=600, top=75, left=75, toolbar=0, menubar=0, location=0, status=0, scrollbars=1, resizable=1");

}

调用此函数的代码

<a href="#"><img src="Images/generatereport_btn.gif" alt="generatereport" border="0" onclick="openGrpLifeStmtReport('busnsourceid','treatyId','policyid','productid','schemename','periodfrom','periodto','plcyeffdtfrom','polcyeffto','benType','exportTo','jasperName','jasperNamesum','reportvar1','reportvar2','reportvar3','reportvar4','userloged','clientId')"/></a> 

1 个答案:

答案 0 :(得分:2)

的问题:

  1. IE允许在仅具有NAME的字段上调用getElementById,其他浏览器不允许这样做,因此请确保表单字段具有ID
  2. 您正在调用此链接中的图像。不推荐的方式。使用链接点击并返回false
  3. OPEN参数中的空格 - 它们可能会破坏某些浏览器中的内容 - target也可能是保留字试试
  4. function openGrpLifeStmtReport (busnsourceid,treatyId,policyid,productid,schemename,periodfrom,periodto,plcyeffdtfrom,polcyeffto,benType,exportTo,jasperName,jasperNamesum,reportvar1,reportvar2,reportvar3,reportvar4,userloged,clientId) {
    
    document.getElementById("reportvar1").value = document.getElementById("busnsourceid").value;
    document.getElementById("reportvar2").value = document.getElementById("treatyId").value;
    document.getElementById("reportvar4").value = document.getElementById("productid").value;
    var Busnsourceid=document.getElementById(busnsourceid).value;
    var TreatyID=document.getElementById(treatyId).value;
    var PolicyID=document.getElementById(policyid).value;
    var ProductID=document.getElementById(productid).value;
    var SchemeName=document.getElementById(schemename).value;
    var PeriodFrom=document.getElementById(periodfrom).value;
    var PeriodTo=document.getElementById(periodto).value; 
    var plcyeffdtfrom=document.getElementById(plcyeffdtfrom).value;
    var polcyeffto=document.getElementById(polcyeffto).value;
    var BenType=document.getElementById(benType).value;
    var exportTo=document.getElementById(exportTo).value;
    var jasperName=document.getElementById(jasperName).value; 
    var jasperNamesum=document.getElementById(jasperNamesum).value; 
    var userloged=document.getElementById(userloged).value;
    var clientId=document.getElementById(clientId).value;
    var disorderby = document.getElementById("orderBy").value;
    var disgroupby = document.getElementById("groupBy").value;
    
    var reportvar3=""; 
    var reportvars = document.getElementsByName("reportvar3");
    for (var i=0; i < reportvars.length; i++) {
      if (reportvars[i].checked) {
        reportvar3 = reportvars[i].value;          
        break;  
      } 
    }
    
    var url = "./GroupLifeAdvRep.do?action=customAction&innerAction=printGrpLifeRep&CedantCode="+Busnsourceid+"&TreatyID="+TreatyID+
            "&Policy Id="+PolicyID+"&ProductID="+ProductID+"&SchemeName="+SchemeName+"&PeriodFrom="+PeriodFrom+"&PeriodTo="+PeriodTo+"&plcyeffdtfrom="+plcyeffdtfrom+"&polcyeffto="+polcyeffto+"&BenType="+BenType+"&exportTo="+exportTo+"&jasperName="+jasperName+"&jasperNamesum="+jasperNamesum+"&reportvar1="+reportvar1+"&reportvar2="+reportvar2+"&reportvar3="+reportvar3+"&reportvar4="+reportvar4+"&disorderby="+disorderby+"&disgroupby="+disgroupby+"&userloged="+userloged+"&clientId="+clientId;
    window.open(url,"_blank","width=850,height=600,top=75,left=75,scrollbars,resiza‌​ble");
    return false; // cancel link            
    }
    

    调用此函数的代码

    <a href="#" onclick="return openGrpLifeStmtReport('busnsourceid','treatyId','policyid','productid','schemename','periodfrom','periodto','plcyeffdtfrom','polcyeffto','benType','exportTo','jasperName','jasperNamesum','reportvar1','reportvar2','reportvar3','reportvar4','userloged','clientId')"><img src="Images/generatereport_btn.gif" alt="generatereport" border="0" /></a>