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)

iFrame within Collapsed Tab not showing correct src set in tabstatechange event

(0) ShareShare
ReportReport
Posted on by 912

crm online - i have a collapsed tab with an iframe in it, when the tab is expanded code fires in the tabstatechange event to set the source of the iframe. Code fires ok but the iframe shows the url set in the form designer, rather than the URL set in the code. If you close it an reopen it it works ok. So how to make it work on the first expansion of the collapsed tab?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PhilKermeen Profile Picture
    912 on at

    I ended up using a setTimeout(function, 300); with the function doing the setSrc on the iFrame from the tabStateChange event

  • Kenneth Heiman Profile Picture
    45 on at

    Sounds like the order of events may be tripping you up. What I've had success with is setting the IFRAME to NOT be visible by default, then in the OnLoad, make the appropriate setSrc call, then setVisible for the IFRAME when I want it to display. I haven't tried loading on the expansion of the tab though.

  • PhilKermeen Profile Picture
    912 on at

    Thanks Kenneth, i had tried that for a while but got a number of errors on attempting to set the iframe visible in code (parent elements null or some such). My solution was working ok in an environment where the legacy form engine was on but appears not to when it's switched off. I'll have another crack tomorrow with your idea

  • Community Member Profile Picture
    on at

    Hi Phil,

    How exactly did you use the setTimeout function? I'm running into the same issue.  I tried using the timeout during the expand event but the src still doesn't get set.

    Thanks in advance.

  • Rasmus R. Aardal Profile Picture
    on at

    Hello Dan,

    When I faced this issue, I ran the setTimeout() in a separate function so that my original function only triggers after the timeout is complete. You can see my simplified code below (Timeout of .5 seconds):

    function tabState()
    {
    setTimeout(function(setURL){500});
    }
    function setURL()
    {
    var frame = Xrm.Page.ui.controls.get("IFRAME_[name]");
    var URL = "[URL]";
    var currentState = Xrm.Page.ui.tabs.get("tab_7").getDisplayState();
    if (currentState == "expanded") {

    frame.setSrc(URL);
    Xrm.Page.ui.tabs.get("tab_7").setLabel("Hide Tab");
    }
    else {
    Xrm.Page.ui.tabs.get("tab_7").setLabel("Show Tab");
    }
    }

  • Suggested answer
    Paresh Jodhani Profile Picture
    67 on at

    I was facing exactly same problem in my D365 environment that my code to set new URL in Iframe inside tab control on tab status change event. One trick worked for me here is using below code:

    //Set Flag to identify tab status change for first time

    i=0;

    function setIframeURL()

    {

    var tabControl = Xrm.Page.ui.tabs.get("tab_mytab");

    if(tabControl.getDisplayState() == "collapsed") return;

    if(i==0)

    {

    i=1;

    tabControl.setDisplayState("collapsed");

    tabControl.setDisplayState("expanded");

    }

    var newURL = "set desired page url here";

    Xrm.Page.getControl("IFRAME_myframe").setSrc(newURL);

    }

    Note: Call "setIframeURL" function on tab status change event in your entity form.

    Regards,

    Paresh

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