web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

setting iframe url in html web resource

(0) ShareShare
ReportReport
Posted on by 7,316

Hi,

I am inserting an iframe in the html web resource and want to set the iframe url with a parameter.

But the iframe always being blank when I test it. What am I doing wrong? how do I set the url?

Here is what I am doing:

<html><head>
    <title></title>
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script> 
<script type="text/javascript">
document.onreadystatechange = function () {
            if (document.readyState == "complete") {
			                SetLeftNavigation();
                       }
        }
  function SetLeftNavigation() {
        var WebPageURL = "http://crm1t/Calendar.aspx"; 
        var userId =window.parent.Xrm.Page.context.getUserId(); //to access userid from entity form
        userId =userId.replace('{', '').replace('}', '');
        var iFramUrl = WebPageURL + "?id=" + userId;
        Xrm.Page.getControl(IFRAME_CustomCalendar).setSrc(iFramUrl);

}
</script> 
</head>
<body style="word-wrap: break-word;">
<iframe id="IFRAME_CustomCalendar" src="about:blank" height="450" width="1000"></iframe>

</body></html>


Someone please guide me. Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Royal King Profile Picture
    27,686 on at

    if you have iframe within the web resource then you have to use id of the control to access and set url for an iframe.  Xrm object model applies only to crm form controls.

    sample code here ,

    document.getElementById('IFRAME_CustomCalendar').src = iFramUrl;

  • meenoo Profile Picture
    7,316 on at

    Thanks Chitra,

    I've changed the line to your suggestion. But the web page still not showing up in the iframe.

    function SetLeftNavigation() {
            var WebPageURL = "http://crm1t/Calendar.aspx";
            var userId =window.parent.Xrm.Page.context.getUserId(); //to access userid from entity form
            userId =userId.replace('{', '').replace('}', '');
     
            var iFramUrl = WebPageURL + "?id=" + userId;
    alert(iFramUrl);
            window.parent.document.getElementById("IFRAME_CustomCalendar").src = iFramUrl;

    }

  • Royal King Profile Picture
    27,686 on at

    why you are using window.parent.document?  

    just use below line that should work.

    document.getElementById("IFRAME_CustomCalendar").src = iFramUrl;

  • Suggested answer
    Surmeet Singh Profile Picture
    3,075 on at

    Hi Meenoo,

    The thing you are trying to achieve can be done with less complexity where you can put a crm iframe instead of iframe in webresource, use js on xrm platform to set the URL of the iframe dynamically.

    Check this example: msdn.microsoft.com/.../gg328034.aspx

  • meenoo Profile Picture
    7,316 on at

    My iframe is not on form.. it's on form. That is the reason why I am using iframe inside html webresource and also to be able to access Xrm objects.

    Thanks.

  • meenoo Profile Picture
    7,316 on at

    Will there be a problem with 'Cross-frame scripting' if I use iframe in html web resource.

    I know we can uncheck 'Restrict cross-frame scripting' if we place a iframe in dashboard to avoid communication issues with the server.

    Is that the reason why I am not able to see the web page in iframe which resides in html web resource? Can we set this property somehow?

    Thanks.

  • Verified answer
    Royal King Profile Picture
    27,686 on at

    Have you tried setting iframe url using below code ?  Iframe is within your webresource so when you execute script in web resource  documents holds all the elelments within the webresorce.

    document.getElementById("IFRAME_CustomCalendar").src = iFramUrl;

  • Suggested answer
    Surmeet Singh Profile Picture
    3,075 on at

    HI Meenoo,

    You can set the URL using of IFrame like

    document.getElementById("myFrame").src = "http://www.cnn.com&quot;;

    and you need to uncheck the crossframe scripting on the control placed on the dashboard else js will not work correctly.

  • meenoo Profile Picture
    7,316 on at

    Hi Chitra,

    Yes I tried setting the iframe url like you suggested:

    document.getElementById("IFRAME_CustomCalendar").src = iFramUrl;

    I did put an alert of iFramUrl and debugged the script as well.. and I see the correct url gets displayed in the alert but it is not assigning it to the iframe src.

    Do I have to have some fire action that calls the function 'SetLeftNavigation()'?

    I know the function gets called when document gets onReadyStateChange but I don't get why my iframe always displays blank!

    Thanks. Please help me.

  • Royal King Profile Picture
    27,686 on at

    your iframe and your site in different origin that may be the cause of the issue. IE probably restricting the reload of the iframe from different site. Use the browser developer tool Network to see the this issue. proess F12 in your page and click on Network traffic in Developer toll and start the network traffic that will show all the request and response that may provide why your iframe not loading

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans