简体   繁体   English

如何在 CRM 2011 中引用 HTML 中的 Javascript 文件

[英]How to refer Javascript file in HTML in CRM 2011

I have created two Javascript webresources with name new_/Scripts/My.JSON2.js and new_/Script/My.RestOperations.js which contains namespace called MYTEST.我创建了两个名为new_/Scripts/My.JSON2.jsnew_/Script/My.RestOperations.js 的 Javascript webresources ,其中包含名为 MYTEST 的命名空间。 And in the same place I created one html page to load when sitemap item is clicked, with name new_/Webpages/My.sitemapPage.htm .在同一个地方,我创建了一个 html 页面以在单击站点地图项时加载,名称为new_/Webpages/My.sitemapPage.htm And I'm trying to call some JSON functions from JScript in html page which are present in "new_/Scripts/My.RestOperations.js" file under MYTEST namespace.我正在尝试从 html 页面中的 JScript 调用一些 JSON 函数,这些函数存在于 MYTEST 命名空间下的“new_/Scripts/My.RestOperations.js”文件中。 In html page I added reference to JScript files as below:在 html 页面中,我添加了对 JScript 文件的引用,如下所示:

<SCRIPT type=text/javscript src="../Scripts/My.RestOperations.js"></SCRIPT>   
<SCRIPT type=text/javscript scr="../Scripts/My.JSON2.js"></SCRIPT>

<SCRIPT type=text/javscript>
function=pageOnLoad()
{
 MYTEST.retrieveMultiple(dataSet,filter,callBackSuccess,callBackError);
}
</SCRIPT>

But still I'm getting an error as:但我仍然收到以下错误:

'MYTEST' is undefined. 'MYTEST' 未定义。

You can access the of the parent window by using window.parent .您可以使用window.parent访问父窗口的

window.parent.MYTEST.retrieveMultiple(dataSet,filter,callBackSuccess,callBackError);

If you try to execute code in the webresource before the load of the parent window's javascript file, you'll have to also put in a try/catch block to handle the fact that the parent file hasn't been loaded.如果您尝试在加载父窗口的 javascript 文件之前执行 webresource 中的代码,则还必须放入 try/catch 块来处理尚未加载父文件的事实。

try {
    var check = window.parent.MYTEST;
} catch (e) {
    setTimeout(function () { pageOnLoad(); }, 1000);
    return;
}

There are two steps.有两个步骤。

  1. Find the url of web resource which you want to refer for example http://servername/organization/WebResources/scriptfile (dont include extention js if it was not shown in url)找到您要引用的 Web 资源的 url,例如http://servername/organization/WebResources/scriptfile (如果 url 中未显示,则不包含扩展 js)

  2. Put that url into html page relatively ie If html file also in WebResources folder then only <script type="text/javascript" src="scriptfile"></script> will work.将该 url 放入 html 页面,即如果 html 文件也在 WebResources 文件夹中,那么只有<script type="text/javascript" src="scriptfile"></script>将起作用。

Note the key is not put any thing extra which is not shown in resource url when you open it from your solution not even extension.请注意,当您从解决方案甚至扩展程序打开它时,该键不会放置任何未显示在资源 url 中的额外内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM