0

同様の質問を調べてみましたが、残念ながら私にとってはうまくいくものはありません。親ドキュメントでクリックすると開くダイアログフォームがあります。値を編​​集した後、フォームは Java サーブレットに送信され、ダイアログを閉じて親に戻ります。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 に答える