简体   繁体   中英

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

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"

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

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

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.

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.

Note that the SDK states that any custom querystring parameters must themselves be encoded and sent via the data parameter.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM