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

Community site session details

Session Id : gHD1xWcCRkcUFfMTVg1Am0
Power Apps - Building Power Apps
Unanswered

IFrame in html web resource

Like (1) ShareShare
ReportReport
Posted on 14 Dec 2022 06:05:26 by 37

Hi hope you guys are fine.

 

I have one html web resource and I have JAVASCRIPT in this html web resource plus I have IFrame in this html web resource as well. I have inserted this html web resource on custom entity form using web resource icon menu on main form of entity.

 

On Page load when i try to access IFrame like this document.getElementById("iframeid") I get IFrame control but when I try to get IFrame using Xrm.Page.ui.controls.get("iframeid") or Xrm.Page.getControl("iframeid") i always get null. 

 

In IFrame I am loading my Canvas app, my canvas app is embeded in model driven app via iframe.

 

just to let you know , I have html iframe in html web resource like this

 

<iframe id="myid"></iframe>

 

I have 3 tabs on form and iframe is on first tab which opens bydefault on page load.

 

I do not want to use document.getElementById because MS does not recommend it when when try to publish our app to MS app source.

 

Any idea what i am doing wrong using XRM api ?

 

 

Categories:
  • zaub Profile Picture
    37 on 14 Dec 2022 at 06:42:35
    Re: IFrame in html web resource

    nope

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on 14 Dec 2022 at 06:41:55
    Re: IFrame in html web resource

    @zaina Does using Xrm.Page.context instead work?

  • zaub Profile Picture
    37 on 14 Dec 2022 at 06:36:59
    Re: IFrame in html web resource

    just to let you know , I have html iframe in html web resource like this

     

    <iframe id="myid"></iframe>

  • zaub Profile Picture
    37 on 14 Dec 2022 at 06:34:01
    Re: IFrame in html web resource

    I can not get form context because it is html web resource. I have tried both but returns null
    window.parent.Xrm.Page  or parent.Xrm.Page 

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on 14 Dec 2022 at 06:22:42
    Re: IFrame in html web resource

    @zaina 

     

    1. Try either window.parent.Xrm.Page (not recommended) or parent.Xrm.Page (better, but the below may be recommended instead)

    2. Use this example of getting form context first using this as a guide:

    //Get the value of an option set attribute
    var formContext = executionContext.getFormContext();
    var value = formContext.getAttribute("new_pagechooser").getValue(); 
    var newTarget = ""; 
    //Set the target based on the value of the option set 
    switch (value) { 
     case 100000001: 
     newTarget = https://myServer/test/pageOne.aspx; 
     break; 
     default: 
     newTarget = https://myServer/test/pageTwo.aspx; 
     break; 
    } 
    //Get the default URL for the IFRAME, which includes the 
    // query string parameters 
    var IFrame = formContext.ui.controls.get("IFRAME_test"); 
    var Url = IFrame.getSrc(); 
    // Capture the parameters 
    var params = Url.substr(Url.indexOf("?")); 
    //Append the parameters to the new page URL 
    newTarget = newTarget + params; 
    // Use the setSrc method so that the IFRAME uses the 
    // new page with the existing parameters 
    IFrame.setSrc(newTarget);

    use executionContext.getFormContext(); to get the context first for example.

    (example from here)

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete