Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

setting iframe url in html web resource

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

  • Suggested answer
    Surmeet Singh Profile Picture
    Surmeet Singh 3,075 on at
    RE: setting iframe url in html web resource

    Hi meenoo,

    Create an CRM iframe on the dashboard and put the url that you are trying to access in that and check if the url is accessible inside crm or not.

  • Royal King Profile Picture
    Royal King 27,686 on at
    RE: setting iframe url in html web resource

    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

  • meenoo Profile Picture
    meenoo 7,316 on at
    RE: setting iframe url in html web resource

    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.

  • Suggested answer
    Surmeet Singh Profile Picture
    Surmeet Singh 3,075 on at
    RE: setting iframe url in html web resource

    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.

  • Verified answer
    Royal King Profile Picture
    Royal King 27,686 on at
    RE: setting iframe url in html web resource

    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;

  • meenoo Profile Picture
    meenoo 7,316 on at
    RE: setting iframe url in html web resource

    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.

  • meenoo Profile Picture
    meenoo 7,316 on at
    RE: setting iframe url in html web resource

    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.

  • Suggested answer
    Surmeet Singh Profile Picture
    Surmeet Singh 3,075 on at
    RE: setting iframe url in html web resource

    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

  • Royal King Profile Picture
    Royal King 27,686 on at
    RE: setting iframe url in html web resource

    why you are using window.parent.document?  

    just use below line that should work.

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

  • meenoo Profile Picture
    meenoo 7,316 on at
    RE: setting iframe url in html web resource

    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;

    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans