locked
How to set iframe src using javascript in crm2013? RRS feed

  • Question

  • Hi 

    I am not able to set iframe src in crm2013.

    I tried with below code but it was not working for me.

    Xrm.Page.getControl("IFRAME_map").setSrc("http://www.microsoft.com");

    Please let me know if any one knows.

    Thanks ,

    sravan J

    Friday, September 27, 2013 1:04 PM

All replies

  • Are you getting any errors when you run that bit of code?

    Please feel free to contact me via any of the following methods:

    Sunday, September 29, 2013 8:32 PM
  • You can try using the following function:

    function SetIFrameUrl(IFrame, Url) {
        var frame = Xrm.Page.ui.controls.get(IFrame);
        frame.setSrc(Url);
    }



    Microsoft Certified Technical Specialist
    EmpowerCS (Australia) for all your CRM/SharePoint needs.
    SharePointBlogger.Net

    Monday, September 30, 2013 2:12 AM
  • Hi Roshan,

    Thanq for respond to my question..

    I am not getting any error..

    Monday, September 30, 2013 12:48 PM
  • Hi Ibrahim,

    Thanq for u r reply

    I tried with u r code also.. still its not displaying any thing in that iframe...


    • Edited by sravan J Monday, September 30, 2013 12:49 PM change
    Monday, September 30, 2013 12:48 PM
  • Put your code on the forum.

    Regards Faisal

    Monday, September 30, 2013 12:58 PM
  • Were you able to resolve this?  I'm having the same problem upgrading from CRM 2011 to CRM 2013.
    Tuesday, October 29, 2013 9:11 PM
  • No David. 
    Wednesday, October 30, 2013 6:51 AM
  • //Get the value of an option set attribute
    var value = Xrm.Page.data.entity.attributes.get("new_pagechooser").getValue();
    var newTarget = "";
    //Set the target based on the value of the option set
    switch (value) {
        case 100000001:
            newTarget = "http://myServer/test/pageOne.aspx";
            break;
        default:
            newTarget = "http://myServer/test/pageTwo.aspx";
            break;
    }
    //Get the default URL for the IFRAME, which includes the 
    // query string parameters
    var IFrame = Xrm.Page.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);
    

    From the CRM 2013 SDK
    • Proposed as answer by F.Kuyler Wednesday, May 28, 2014 12:18 PM
    Thursday, October 31, 2013 8:52 AM
  • I am having the exact same problem. So far I have only tested on CRM online, but I will try to do a test on-prem tomorrow and then I will open an SR with MS as there a no solutions posted anywhere.

    Tuesday, November 5, 2013 11:10 AM
  • Did you end up having the same issue with on-premise?
    • Proposed as answer by Igor Abreu Monday, November 11, 2013 4:50 PM
    • Unproposed as answer by Igor Abreu Monday, November 11, 2013 4:50 PM
    Monday, November 11, 2013 2:35 PM
  • i'm having the same problem using on-premise, the sdk reccomends you use a follow code:

    setSrc

    Sets the URL to be displayed in an IFRAME or web resource.


    Xrm.Page.getControl(arg).setSrc(string)

    But i don't have sucess!
    • Edited by Igor Abreu Monday, November 11, 2013 4:53 PM
    Monday, November 11, 2013 4:52 PM
  • 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:26 AM
  • Brilliant, Mohamed.  This worked for me.  Thanks very much.
    Wednesday, November 13, 2013 4:56 PM
  • This doesn't work for me, I may be using the OnReadyStateComplete feature wrong.How do I register a function for OnReadyStateComplete?

    Can someone elaborate on what that is supposed to do and how it works?

    All I want to do is load a different URL into an IFrame, no luck so far.

    Friday, December 13, 2013 7:40 PM
  • DuSport, it's a bit late but select the IFram then click on "Change Properties". Navigate to the tab "Events". There you will se the OnReadyStateComplete event listed.
    Tuesday, May 20, 2014 3:56 AM