0

我已经搜索了所有类似的问题,但不幸的是,似乎没有一个对我有用。我有一个对话框表单,它在父文档中单击时打开。编辑完值后,表单被提交给 java servlet,关闭对话框并返回到父级。在 Chrome 或 Firefox 中一切正常,但是在 IE 中它会打开一个带有响应 URL 的空白页面。解决方案将非常有帮助,但任何指针都应该没问题。

父 JSP:

<body class="yui3-skin-sam">
    <center>
        <div id="ok">
        <h1>NBReports</h1>
        <p>New business on call reports</p><br/>        
        <input type="button" value="Add Row" align="right" onclick="javascript: showWindow(window, 1)" /><br/>      
        <div id="tblReportSchedule"></div><br/>
        <input type="button" value="Add Row" align="right" onclick="javascript: showWindow(window, 1)" />
        </div>
    </center>
</body>
<script type="text/javascript">

function showWindow(obj, bEdit)
{   
    if(bEdit == 1)
        {
            openModal("updateSchedule.jsp", 600, 450);
        }
    else if(bEdit == 2)
        {   
            var rowID = obj.parentNode.parentNode.parentNode.parentNode.id; 
            openModal("updateSchedule.jsp", 600, 450, getAllRowValuesbyID(rowID));
        }
    else 
        {
            var rowID = obj.parentNode.parentNode.parentNode.parentNode.id; 
            openModal("updateSchedule.jsp", 300, 200, getAllRowValuesbyID(rowID).split("/")[0]);            
        }
}

function getAllRowValuesbyID(rowID)
{
    var rowValues="";
    row = document.getElementById(rowID);

    for (var i = 0; i < row.childNodes.length; i++) {
        if((window.navigator.userAgent.toLowerCase().indexOf('windows') == -1) )
        {
            var node = row.childNodes[i];
            rowValues += node.textContent + "/";
        }
        else
        {
            var node = row.children[i];
            rowValues += node.outerText + "/";  
        }
    }
    return rowValues;
}

function openModal(url, width, height, rowValues)
{
    var features = "";
    if (width != "")
    {
    features = features + "dialogWidth:" + width + "px;";
    }
    if (height != "")
    {
        features = features + "dialogHeight:" + height + "px;";
    }

    var retVal = window.showModalDialog(url, rowValues, features);  

    if(retVal)
    {
        document.location.reload(true);
    }
}

</script>

</html>

对话框形式:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update Schedule Form</title>

<script type="text/javascript">
    function onSubmit()
    {
        window.returnValue = "";
        if((window.opType == 3) || window.dirtyFlag)
        {   
            window.dirtyFlag = 1;
            window.returnValue = getValue('cronTab') + '/' + 
                                 getValue('reportName') + '/' +
                                 getValue('subject') + '/' +
                                 getValue('recipient') + '/' +
                                 getValue('cc') + '/' +
                                 getValue('database') + '/' +
                                 getValue('script') + '/' +
                                 getValue('format');
        }
        window.close();
    }

    function getValue(varName)
    {
        if(document.getElementById(varName) == null)
            return "";
        if(document.getElementById(varName).value == null)
            return "";
        else
            return document.getElementById(varName).value;
    }

    function setdirtybit()
    {
        window.dirtyFlag = 1;
    } 

    function SubmitForm()
    {
        if(window.navigator.userAgent.toLowerCase().indexOf('chrome') == -1)
        {
            if(window.dirtyFlag || window.opType == 3)
            {
                document.forms["UpdateSchedule"].method="get";
                document.forms["UpdateSchedule"].action="/nbreports/updates";
                document.forms["UpdateSchedule"].target="_self";
                document.forms["UpdateSchedule"].submit();
            }
        }
    }

    function GenerateSubmit(valText)
    {
        var submitButton = "";
        if(window.navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
            submitButton = "<center><input type ='submit' value='" + valText + "' onclick='onSubmit()' /></center>";            
        else
            submitButton = "<center><input type ='button' value='" + valText + "' onclick='onSubmit()' /></center>";

        return submitButton;
    }   

    window.onbeforeunload = SubmitForm;
    </script>
</head>
<body>  
    <form name="UpdateSchedule" id = "UpdateSchedule" action="/nbreports/updates" method="get">
        <script type="text/javascript">
        var valuesArray = new Array();
        if(typeof window.dialogArguments == "undefined")
        {
            var idArray=["cronTab","reportName","subject","recipient","cc","database","script","format"];
            var nameArray=["CronTab","Report Name","Message Subject","Recipient List","Cc","Database","Script","Format"];

            var str = "<table cellpadding = '2' border = '0'>";

            for(var i = 0; i < 8; i++){
                str += "<tr>";
                str += "<td><label for='" + nameArray[i]+"'>" + nameArray[i] + "</label></td>"; 
                if(i==3 || i==4){
                    str += "<td><input style='width:450px' type ='text' id='" + idArray[i] + "' name='" + nameArray[i] + "' onchange='setdirtybit()' /></td>";
                }
                else{str += "<td><input style='width:200px' type ='text' id='" + idArray[i] + "' name='" + nameArray[i] + "' onchange='setdirtybit()' /></td>";}
                str += "</tr>";
            }
            str += "<tr style='display: none;'><input type='hidden' name='opType' value='1' /></tr>";
            str += "</table>";

            document.write(str);        
            document.write(GenerateSubmit("Submit"));   
        }
        else 
        {
            valuesArray=window.dialogArguments.split("/");
            if(valuesArray.length == 1)
            {
                document.write("<center><label>Are you sure you want to delete the row?</label><br/><br/></center>");
                document.write("<input type='hidden' name='id' value='"+ valuesArray[0] +"' />");
                document.write("<input type='hidden' name='opType' value='3' />");
                document.write(GenerateSubmit("Ok"));
                window.opType = 3;
            }
            else
            {       
                var idArray=["cronTab","reportName","subject","recipient","cc","database","script","format","id"];
                var nameArray=["CronTab","Report Name","Message Subject","Recipient List","Cc","Database","Script","Format", "Id"];

                var str = "<table cellpadding = \"2\" border = \"0\">";

                for(var i = 0; i < 8; i++){
                    str += "<tr>";
                    str += "<td><label for='" + nameArray[i]+"'>" + nameArray[i] + "</label></td>"; 
                    if(i==3 || i==4){
                        str += "<td><input style='width:450px' type ='text' id='" + idArray[i] + "' name='" + nameArray[i] + "' onchange='setdirtybit()' /></td>";
                    }
                    else{str += "<td><input style='width:200px' type ='text' id='" + idArray[i] + "' name='" + nameArray[i] + "' onchange='setdirtybit()' /></td>";}
                    str += "</tr>";
                }
                str += "<tr style='display: none;'><input  type ='hidden' name='id' value='"+ valuesArray[0] +"'/></tr>";
                str += "<tr style='display: none;'><input  type ='hidden' name='opType' value='2' /></tr>";
                str += "</table>";

                document.write(str);
                for(var i = 0; i < 8; i++){
                    document.forms[0].elements[nameArray[i]].value = valuesArray[i+1];
                }
                document.write(GenerateSubmit("Submit"));
            }
        }               
        </script>
    </form>
</body>

</html>
4

1 回答 1

0

我认为是因为 document.write(); 你可以用使用 innerHTML 来代替它吗?!而不是 document.write(str); Document.write(GenerateSubmit("提交")); 试试,document.getElementById("submitNode").innerHTML = str+GenerateSubmit("Submit");

请记住在表单中添加一个 id 为“submitNode”的 div 元素。像这样:

于 2012-09-21T18:31:12.140 回答