admin管理员组

文章数量:1400681

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.

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.

Share Improve this question asked May 24, 2012 at 7:33 user1173691user1173691 4432 gold badges7 silver badges15 bronze badges 3
  • does window.onload=function() { alert(location.search); } work for you? – mplungjan Commented May 24, 2012 at 7:41
  • you can set iframe url, and after in form load call javascript function, with something like: var userId = crmForm.all.new_id.value; var detailsIframe = crmForm.all.IFRAME_contactdetails; detailsIframe.src = detailsIframe.src + '?Id=' + userID; – lazarus Commented May 24, 2012 at 11:11
  • 2 crmForm... notation is deprecated in CRM 2011 – Greg Owens Commented May 24, 2012 at 11:27
Add a ment  | 

1 Answer 1

Reset to default 4

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

本文标签: CRM 2011 Passing values to IFRAMEWeb Resource with javascriptStack Overflow