CRM:打开一个网站并获取结果

时间:2015-12-01 07:34:32

标签: javascript crm

我的方案是在点击按钮后在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字符

如何传递此错误并将结果发送给开场白?

1 个答案:

答案 0 :(得分:1)

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

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

在您的外部网页中:

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

希望这有帮助。