CRM:打开网站并返回结果

CRM: open a website and get back result

我的场景是在 CRM 中单击一个按钮后,它会弹出一个外部网页 (ASPX),这个网页只是一个搜索页面。我想取回此页面中的选择项以更新 CRM 页面。

我正在使用此代码打开对话框:

function openAddressSearch(addressType) {
    searchAddressType = addressType;
    //Allow for borders.
    var width = window.screen.width * 2/3;
    var height = window.screen.height * 2/3;
    var leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Allow for title and status bars.
    var topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    //Open the window.
    var addressSearch = window.open("http://localhost:2402/", "AddressSearch",
        "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition +
        ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
/*    addressSearch.callback = function (result) {
        alert(result);
    }*/
    if (window.focus) {
        addressSearch.focus();
    }
}

function addressSearchResult(result) {
    alert(result);
}

在网页(aspx)中,点击选择按钮,我调用了一个js函数:

    <script type="text/javascript">
        myClosure = function () {
            window.opener.addressSearchResult("CALLBACK");
            window.close();
        }
</script>

<asp:Button runat="server" ID="m_btnSelect" Text="<%$ Resources: myResource, Select %>" OnClientClick="myClosure();"/>

但是单击 btnSelect 后,我​​在行出现错误:

        window.opener.addressSearchResult("CALLBACK");

SCRIPT70:权限被拒绝 localhost:2402, 第 11 行字符 13

我应该怎么做才能传递此错误并将结果发送回开场程序?

您可以使用事件监听器,在您的 openAddressSearch 中,将以下事件监听器添加到当前 window:

window.addEventListener("message", function (result) {
    alert("CALLBACK");
});

在您的外部网页中:

window.opener.postMessage(address, "yourParentPageUrl");

希望对您有所帮助。