无法在 Crm 中使用 Javascript 关闭对话框 window

Cannot close dialog window using Javascript in Crm

我无法使用 Microsoft Dynamics CRM 2016 中的 javascript 关闭功能区中按钮的单击事件打开的对话框 window(单击取消按钮)。我是Crm 的初学者。我将不胜感激任何帮助。提前谢谢你。

这是打开对话框的代码:

    function NewDialog() 
{
var DialogOptions = new Xrm.DialogOptions();
DialogOptions.width = 500;
DialogOptions.height = 500;
debugger;
window.parent.Xrm.Internal.openDialog(Mscrm.CrmUri.create("/WebResources/new_popupDialog").toString(), DialogOptions, null, null, CallbackFunction);
    function CallbackFunction(oReturn) { 

     }
    }

这是对话框 window 的 Web 资源 HTML 代码:

<html><head>
    <title></title>
    <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script>
</script>
    <style type="text/css">
        body {
            direction: LTR;
            margin: 0px;
            border: 0px;
            cursor: default;
            font-family: Segoe UI,Tahoma,Arial;
            font-size: 11px;
        }

        .ms-crm-RefreshDialog-Header {
            top: 0px;
            position: absolute;
            width: 96%;
            height: 75px;
            padding-top: 10px;
            background-color: #FFFFFF;
            border-bottom-color: #A4ABB2;
        }

        DIV.ms-crm-RefreshDialog-Header-Title {
            font-weight: Lighter;
            font-size: 27px;
            font-family: Segoe UI Light, Segoe UI, Tahoma, Arial;
            margin-left: 30px;
            margin-right: 30px;
            color: #262626;
        }

        .ms-crm-TextAutoEllipsis {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .ms-crm-RefreshDialog-Header-Desc {
            padding-top: 4px;
            font-family: Segoe UI,Tahoma,Arial;
            margin-left: 30px;
            margin-right: 30px;
            color: #666666;
            font-size: 12px;
        }

        .ms-crm-RefreshDialog-Main {
            font-size: 12px;
            top: 90px;
            position: absolute;
            bottom: 49px;
            vertical-align: top;
            width: 95%;
            font-family: Segoe UI,Tahoma,Arial;
            color: #444444;
            background-color: #FFFFFF;
            border-bottom-color: #A4ABB2;
            right: 30px;
            left: 30px;
        }

        .ms-crm-RefreshDialog-Footer {
            position: absolute;
            bottom: 0px;
            width: 100%;
            min-width: 288px;
            height: 44px;
            text-align: right;
            background-color: #F8F8F8;
            border-top-color: #FFFFFF;
        }

        .ms-crm-RefreshDialog-Button {
            color: #444444;
            background-color: #FFFFFF;
            height: 24px;
            font-family: Segoe UI,Tahoma,Arial;
            border: 1px solid #C6C6C6;
            background-image: none;
            margin-top: 10px;
            width: auto;
            min-width: 80px;
            white-space: nowrap;
            font-size: 12px;
            line-height: 16px;
            width: 84px;
            text-align: center;
            cursor: pointer;
            background-repeat: repeat-x;
            padding-left: 5px;
            padding-right: 5px;
        }
    </style>
<meta charset="utf-8"></head>
<body>
    <div class="ms-crm-RefreshDialog-Main-Container" style="font-family: undefined;">
        <div class="ms-crm-RefreshDialog-Header" id="tdDialogHeader">
            <div title="Your dialog header" class="ms-crm-RefreshDialog-Header-Title ms-crm-TextAutoEllipsis" id="dialogHeaderTitle" style="width: 75%;">My Custom Page</div>
            <div title="Your dialog additional description" class="ms-crm-RefreshDialog-Header-Desc" id="dialogHeaderDesc">Rohit</div>
            <div class="ms-crm-RefreshDialog-Main" id="DlgHdBodyContainer">
                <form action="demo_form.asp">
                    First name:&nbsp;&nbsp; <select id="selectmenu"><option selected="selected" value="">                    Select an option                 </option>                 <option value="option1">Option One</option>                 <option value="option2">Option Two</option>                 <option value="option1N">Option N</option>             </select><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                </form>
            </div>
        </div>
        <div class="ms-crm-RefreshDialog-Footer" id="tdDialogFooter">
            <button tabindex="1" class="ms-crm-RefreshDialog-Button" id="btnOK" style="margin-left: 8px;" onclick="window.parent.Mscrm.Utilities.setReturnValue(true); window.parent.closeWindow();" type="button">
                OK
            </button>
            <button tabindex="1" class="ms-crm-RefreshDialog-Button" id="cmdDialogCancel" style="margin-right: 30px; margin-left: 8px;" onclick="window.parent.closeWindow();" type="button">
                Cancel
            </button>
        </div>
    </div>


</body></html>

这是对话框的屏幕截图:

我知道问题出在哪里了。谢谢你。 替换

src="../ClientGlobalContext.js.aspx"

src="ClientGlobalContext.js.aspx"

您可以在右上角获得按钮 XID。然后运行.

document.getElementById("InlineDialogCloseLink").click();

InlineDialogCloseLink 是按钮的 ID X

您可以使用 js 从 Webresource 如下单击 X(右上角的关闭按钮)

window.parent.document.getElementById('InlineDialogCloseLink').click()