CRM 2011:使用 javascript 将值传递给 IFRAME/Web 资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10733086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:50:53  来源:igfitidea点击:

CRM 2011: Passing values to IFRAME/Web Resource with javascript

javascriptdynamics-crm-2011

提问by user1173691

I've looked at a few different articles and the they all seem to suggest the same thing:

我看了几篇不同的文章,它们似乎都在暗示同样的事情:

"Create a url with the desired query parameters and set the target iFrame with this new Url and have this new page read the request"

“使用所需的查询参数创建一个 url,并使用这个新的 Url 设置目标 iFrame,并让这个新页面读取请求”

I was wondering if there was a way of doing this without the use of a custom ASPX page?

我想知道是否有办法在不使用自定义 ASPX 页面的情况下做到这一点?

Essentially I would like to dynamically display some text in either an iFrame or html web resource based on some values on the form.

本质上,我想根据表单上的某些值在 iFrame 或 html Web 资源中动态显示一些文本。

回答by Greg Owens

There is nothing in the SDK that mandates use of ASPX. In fact in CRM 2011 it is discouraged as you'd need to find somehwere to host your ASP.Net page.

SDK 中没有任何内容要求使用 ASPX。事实上,在 CRM 2011 中是不鼓励的,因为您需要找到某个地方来托管您的 ASP.Net 页面。

With a basic HTML page (created as a web resource in CRM) you can declare some JScript in the HEAD of the HTML document (or better still, reference a JScript web resource). That JScript could read the querystring parameters sent via the iFrame and do whatever is required from there.

使用基本的 HTML 页面(在 CRM 中创建为 Web 资源),您可以在 HTML 文档的 HEAD 中声明一些 JScript(或者更好的是,引用 JScript Web 资源)。该 JScript 可以读取通过 iFrame 发送的查询字符串参数,并从那里执行任何需要的操作。

Note that the SDK statesthat any custom querystring parameters must themselves be encoded and sent via the dataparameter.

请注意,SDK 声明任何自定义查询字符串参数本身都必须经过编码并通过data参数发送。

<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Example page</TITLE>
<META charset=utf-8></HEAD>
<BODY style="BACKGROUND-COLOR: #f6f8fa; MARGIN: 0px; FONT-FAMILY: Segoe UI" contentEditable=true onload="doStuff">
<SCRIPT type=text/jscript>

function doStuff(){
    getQueryStrings();
    alertOrganisationName();
}

function alertOrganisationName(){
    alert(window.parent.Xrm.Page.context.getOrgUniqueName());
}

function getQueryStrings() {
    var message = document.getElementById("myOutputArea");
    var dataParameterString, querystring;
    // get data from querystring
    if (window.location.search != "") {
        querystring = window.location.search.substr(1).split("&");
        for (var i in querystring) {
            querystring[i] = querystring[i].replace(/\+/g, " ").split("=");
        }
        //look for the parameter named 'data'
        for (var i in querystring) {
            if (querystring[i][0].toLowerCase() == "data") {
                dataParameterString = querystring[i][1];
                break;
            }
        }

        message.innerText += dataParameterString;

    } else {
        message.innerText = "No details were specified in the querystring.";
        alert("ERROR: " + message.innerText);
    }
}       
 </SCRIPT>
 <DIV id="myOutputArea"></DIV>
</BODY></HTML>