Wednesday, March 20, 2019

Showing external website in IFrame in Dynamics 365.


Probably the most common page for a developer is www.google.com

I was trying IFrame component in dynamic 365 CRM and Google being my favorite, I tried to render Google.com to an Iframe within Microsoft Dynamic CRM.

I was unable to render Google.com to an Iframe within Dynamic 365 CRM.

This is NOT at all a dynamic 365 CRM problem, we cannot (in a simple way) render Google page within an IFrame. You can try in W3Schools.com too.


Reason:

Google sends a "X-Frame-Options: SAMEORIGIN" response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page.



Note: 
Try loading some other website in an IFrame within Dynamic CRM and it should work like a charm.

Some common blogs or something – I used my own blog - https://vjcity.blogspot.com/

Modifying URL of IFrame by passing parameter using JavaScript.


A URL is mandatory attribute when inserting an IFrame on a form. Let’s populate it with URL with only base address of our desired website and passing the required parameter from JavaScript.


JavaScript Code to pass a record id (Guid) to an IFrame URL.

Call this function on the load of the form.

function passIdtoIframe()
{
    var recordId = Xrm.Page.data.entity.getId();
    recordId = id.replace("{", "").replace("}", "")

    var IFrame = Xrm.Page.ui.controls.get("IFRAME_Contact_view");

    var UrlwithIdAppended = IFrame.getSrc() + recordId;

    IFrame.setSrc(UrlwithIdAppended);
}


Breaking an Ice: What if, I really need to display google search result within Dynamic CRM by passing some parameter? Can we achieve this or not?

I will update blog with some more findings. 

Hope this help!

Thanks.
Vipin Jaiswal
vipinjaiswal12@gmail.com

2 comments:

Vinisz said...

Hi,

Ver good article, I like it.
What I want to do is to set the Iframe URL to the value of the "cr8bd_imageurl" field of the entity "product"
Would that be possible as well ? I think something like below ?

Hope you can help me out with this.

var description = parent.Xrm.Page.getAttribute("cr8bd_imageurl").getValue();
document.getElementById("cr8bd_imageurl").innerHTML = description;




Vipin Jaiswal said...

var description = parent.Xrm.Page.getAttribute("cr8bd_imageurl").getValue();
var IFrame = Xrm.Page.ui.controls.get("IFRAME_Contact_view");
IFrame.setSrc(description);

Try this code, document.getElementById is not the solution here...