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 my form.
Now, because of the size of the code, I feel the need to refactor it and I'd like to move out some of the methods from the script tag of my HTML web resource to a separate JS web resource.
At the first step I've set up the separate JS web resource as follows.
function test() { alert("Success."); }
From the script inside the HTML document I execute the following, getting an error as test seems not to be known to the page.
alert("Get ready for test...");
test();
alert("Did it work?");
I've added the JS web resource to the form and savepublished, of course. There's surprisingly little info on the subject out there. I've found those links but none of them matches exactly what I need and gives me no hint on how to approach the issue at hand.
- This link resembles what I want to achieve but it's about calling JS from JS where both are web resources.
- This link is diagonally opposite to what I want but I don't know how to reverse it from calling HTML from JS whre both are web resources.
What should I correct?
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 my form.
Now, because of the size of the code, I feel the need to refactor it and I'd like to move out some of the methods from the script tag of my HTML web resource to a separate JS web resource.
At the first step I've set up the separate JS web resource as follows.
function test() { alert("Success."); }
From the script inside the HTML document I execute the following, getting an error as test seems not to be known to the page.
alert("Get ready for test...");
test();
alert("Did it work?");
I've added the JS web resource to the form and savepublished, of course. There's surprisingly little info on the subject out there. I've found those links but none of them matches exactly what I need and gives me no hint on how to approach the issue at hand.
- This link resembles what I want to achieve but it's about calling JS from JS where both are web resources.
- This link is diagonally opposite to what I want but I don't know how to reverse it from calling HTML from JS whre both are web resources.
What should I correct?
Share Improve this question edited May 23, 2017 at 12:21 CommunityBot 11 silver badge asked Dec 8, 2012 at 12:56 user1675891user1675891 3- @eicto And how exactly would you get the JavaScript into the server if it's not a web resource? (I've got more than the basics of JS, I'm just not sure how to refer a function in an other web resource. And frankly, I'm not sure that you do neither. My code works - I just wish to refactor it.) – user1675891 Commented Dec 8, 2012 at 13:48
- 2 @eicto Not to burst your bubble but the OP did have the tag of CRM Dynamics. I've checked your page and I'm sure that you're a great JS programmer but I think you're missing that MS has managed to make things hrmp... different, when it es to putting JS into CRM. If you don't get the importance of web resource in CRM, you shouldn't get too cocky criticizing him/her. It is stated in the ment that it's a matter of refactoring a working code. That implies that the basic understanding of JS is ensured. And frankly, It's not that plicated to get JS working on a basic level. – Konrad Viltersten Commented Dec 8, 2012 at 14:00
- yes, i just wanted to show OP a way where he will see simple things in plex problems. I not great JS programmer :) and i mostly not programmer at all, my main job is system administration :) – zb' Commented Dec 8, 2012 at 14:23
3 Answers
Reset to default 2Calling 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;
function test() { alert("Success."); }
HTML webresource:
window.parent.Xrm.Page.test();
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.
- Contact Microsoft. You've just found a serious bug.
- Watch out. There will be pigs flying very soon.
- 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.)
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?");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745577085a4634030.html
评论列表(0条)