locked
CRM 2013: Iframe does not display the url set in onform load event with setSrc. How to make this work? RRS feed

  • Question

  • I have a situation we need to display a url in Iframe when a form is loading. the url is set in code with setSrc, or updated the query string value. this worked in crm 2004 not any more in 2013.  MSDN states the below to avoid in OnLoad event. what is the best way to handle this situation?  Searched web people recommend using setInterval which i dont want to use.

    Any help on this issue is appreciated. 

    https://msdn.microsoft.com/en-us/library/gg328034(v=crm.6).aspx

    Avoid using the OnLoad Event. IFRAMES and web resources load asynchronously and the frame may not have finished loading before the Onload event script finishes. This can cause the src property of the IFRAME or web resource you have changed to be overwritten by the default value of the IFRAME or web resource URL property.

    Friday, February 20, 2015 11:49 PM

Answers

  • thank you for your response. having the code wired to OnReadyStateComplete does the trick.


    function Iframe_OnReadyStateComplete () {
        var iFrame = Xrm.Page.ui.controls.get('IFRAME_docmgmt');
        var url = iFrame.getSrc();
        if (url.indexOf("blank") != -1) {
            setiFrameUrl();
        }
    }

    function setiFrameUrl() {
        var url = 'http://www.google.com';
        Xrm.Page.getControl('IFRAME_docmgmt').setSrc(url);
    }

    reference:
    http://stackoverflow.com/questions/22390328/how-to-set-an-iframe-src-attribute-set-in-crm-2013-using-javascript 
    • Marked as answer by Geo Manickam Tuesday, February 24, 2015 8:52 PM
    Tuesday, February 24, 2015 8:52 PM

All replies

  • Saturday, February 21, 2015 9:28 AM
  • Hey,

    Set default URL to blank in IFrame properties.

    Here is the sample code that worked for me.

     var iframeObject = Xrm.Page.getControl("IFRAME_Frame");
        var strIframeURL = iframeObject.getSrc();
        if (strIframeURL == 'about:blank' || strIframeURL == '/_static/blank.htm' || strIframeURL == '') {// Check if url is blank and then proceed.
            iframeObject.setSrc('');
            iframeObject.setSrc(strURL);
        }

    Hope it helps you.

    Jugal Kishore D

    Monday, February 23, 2015 5:51 AM
  • Thank you for you reply.  this URL you send uses window.setInterval which i am not comfortable using it. we need to call clearInterval(), if not the IFrame refresh every second. 

    function SetURL()

    {

    if(Xrm.Page.ui.controls.get("IFRAME_ActivitySmmary")!=null)

    {

    Xrm.Page.ui.controls.get("IFRAME_ActivitySmmary").setSrc(reportUrl + "&id="+ customerId);
                    Xrm.Page.ui.controls.get("IFRAME_ActivitySmmary").setVisible(true);

    }

    else

    { window.setInterval("SetURL()",1000);}

    }

    Monday, February 23, 2015 5:26 PM
  • Thank you Jugal,  we have similar code, CRM 2013 overide the url set when the page is completely rendered by CRM :(.

    Looks like there is no way to make this work. without hack window.setInterval.


    Monday, February 23, 2015 5:27 PM
  • Rather using window.setInterval, use a flag and skip reloading using that. Even I did that.
    var _vrFlag = 0;
    function abc() {
      if (_vrFlag == 0) {
        _vrFlag = 1;
        var iframeObject = Xrm.Page.getControl("IFRAME_Frame");
        var strIframeURL = iframeObject.getSrc();
        if (strIframeURL == 'about:blank' || strIframeURL == '/_static/blank.htm' || strIframeURL == '') {// Check if url is blank and then proceed.
            iframeObject.setSrc('');
            iframeObject.setSrc(strURL);
        }
      }
    }


    Jugal Kishore Dandamudi.

    Tuesday, February 24, 2015 9:09 AM
  • thank you for your response. having the code wired to OnReadyStateComplete does the trick.


    function Iframe_OnReadyStateComplete () {
        var iFrame = Xrm.Page.ui.controls.get('IFRAME_docmgmt');
        var url = iFrame.getSrc();
        if (url.indexOf("blank") != -1) {
            setiFrameUrl();
        }
    }

    function setiFrameUrl() {
        var url = 'http://www.google.com';
        Xrm.Page.getControl('IFRAME_docmgmt').setSrc(url);
    }

    reference:
    http://stackoverflow.com/questions/22390328/how-to-set-an-iframe-src-attribute-set-in-crm-2013-using-javascript 
    • Marked as answer by Geo Manickam Tuesday, February 24, 2015 8:52 PM
    Tuesday, February 24, 2015 8:52 PM