Skip to content Skip to sidebar Skip to footer

Calling A Js Function From Html Iframe (both Web Resources)

I've uploaded two web resources, a.HTML and b.JS. In the HTML document I have a section where a script is executed (and it works as supposed to) upload loading into the IFRAME on m

Solution 1:

Calling a function in a javascript webresource, from an HTML webresource in Microsoft Dynamics CRM

CRM 2015

Javascript webresource:

function test() { alert("Success."); }

HTML webresource:

window.parent.test();

CRM 2016

They now load HTML webresources in an Iframe so you can't access external js files, but you can access the XRM object. So you can place the function on this object.

Javascript webresource:

Xrm.Page.test = test;
functiontest() { alert("Success."); }

HTML webresource:

window.parent.Xrm.Page.test();

Solution 2:

Check the following assumptions that you did:

  • save the web resource?
  • publish all changes?
  • add the resource to the frame in the regarded entity?
  • name the function hazaa
  • call the correct name, i.e. parent.window.test()?

If yes to all of the above, do three things.

  1. Contact Microsoft. You've just found a serious bug.
  2. Watch out. There will be pigs flying very soon.
  3. Get a coat. It's about to get much colder.

(By that, I mean that you surely have missed on something in the list I've provided and that you need not to contact Microsoft, pigs won't start to fly and the hell won't freeze over.)

Solution 3:

I think your test() function is in scope of your html document's window. and when you call it from inside the iframe's document, it searches for test() in its scope.

Try out

alert("Get ready for test...");
parent.window.test();
alert("Did it work?");

and in case the test() is defined in the iframe and you are calling it from the HTML document try this.

alert("Get ready for test...");
document.getElementById("iframeId").src ="javascript:test();"alert("Did it work?");

Post a Comment for "Calling A Js Function From Html Iframe (both Web Resources)"