locked
CRM 2013: JSCRIPT SetSrc() function doesn't seem to work on a form's onLoad() RRS feed

  • Question

  • Hello,

    I have the following jScript on the onLoad event of a custom entity's form, which is supposed to load a new URL in an IFRAME:

    function bingMapsLoader() {
       var val_Latitude = Xrm.Page.data.entity.attributes.get("pmdci_latitude").getValue();
       var val_Longitude = Xrm.Page.data.entity.attributes.get("pmdci_longitude").getValue();
       
       if (!val_Latitude && !val_Longitude)  { return; }
    
       bingMapURL = 'http://www.bing.com/maps/embed/viewer.aspx?v=3&cp=' + val_Latitude + '~' + val_Longitude + '&lvl=4&w=600&h=400&sty=r&typ=d&pp=&ps=&dir=0&mkt=en-gb&form=BMEMJS';
       Xrm.Page.ui.controls.get("IFRAME_bingmap").setSrc(bingMapURL);
       Xrm.Page.ui.tabs.get("tab_General").sections.get("sec_BingMap").setVisible(true);
    }

    As you can see, the code is pretty basic. However, the IFRAME doesn't load the URL in the iFRAME, which continues to be blank (default is 'about:blank'). Yet, the Jscript doesn't return any errors. The code seems to be valid.

    In fact, if I change the bingMapUL variable above to something trivial, like 'http://www.bing.com', the iFRAME still doesn't load the URL.

    NOTE: I did uncheck the option to restrict cross-frame scripting. 

    If I add any URL into the iFRAME's default URL, it loads without any issues. The only issue seems to be with a script asking to change the URL.

    No problem with my IF statement either. I have tried the setSrc() function plain and simple to point to whatever URL, and still it doesn't seem to work.

    What is that I am doing wrong? :(

    Thanks in advance for the help.

    Regards,

    P.



    • Edited by pmdci Tuesday, November 5, 2013 10:55 PM
    • Changed type pmdci Tuesday, November 5, 2013 11:23 PM mistake
    Tuesday, November 5, 2013 10:54 PM

All replies

  • Hi,

    I faced this problem also, the solution is a small work around in few steps.

    1- Set IFrame URL to "about:blank".

    2-Register function for IFrame's OnReadyStateComplete as following :

    function setIFRAME_Related_PO_OnLoad() {
        var IFrame = Xrm.Page.ui.controls.get("IFRAME_Related_PO");
        var url = IFrame.getSrc();
        if (url.indexOf("blank") !== -1) {
            setIFRAME_Related_PO();
        }
    }

    3-setIFRAME_Related_PO is a normal function to set url for IFrame Example Code:-

    function setIFRAME_Related_PO() {
            var url = 'www.google.com';
    
            Xrm.Page.getControl('IFRAME_Related_PO').setSrc(url);
    }

    I hope this be useful for you.

    Mohamed Rasheed

    EgyptianProgrammer@hotmail.com

    Wednesday, November 13, 2013 9:25 AM