Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

Posted on by 910

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

  • Suggested answer
    Paresh Jodhani Profile Picture
    Paresh Jodhani 67 on at
    RE: iFrame within Collapsed Tab not showing correct src set in tabstatechange event

    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

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

    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");
    }
    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: iFrame within Collapsed Tab not showing correct src set in tabstatechange event

    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.

  • PhilKermeen Profile Picture
    PhilKermeen 910 on at
    RE: iFrame within Collapsed Tab not showing correct src set in tabstatechange event

    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

  • Kenneth Heiman Profile Picture
    Kenneth Heiman 45 on at
    RE: iFrame within Collapsed Tab not showing correct src set in tabstatechange event

    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.

  • Suggested answer
    PhilKermeen Profile Picture
    PhilKermeen 910 on at
    RE: iFrame within Collapsed Tab not showing correct src set in tabstatechange event

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

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans