如何从其他web资源(html)调用web资源(html)函数



我使用的是Dynamics CRM,其中我们在同一表单上有两个不同的web资源。现在,当我试图从一个web资源调用java脚本函数到另一个时,它给出了以下错误。

Message: Object expected
Line: 10
Char: 1
Code: 0
URI: http://dynamicscrm01/CRM01/%7B635481860480000809%7D/WebResources/new_htmlWithBorder

我正在尝试调用toggle1()函数。

被呼叫方Web资源代码:

  <title>T</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js"></script>
    <script>
        var x = 0;
    function  toggle1() {
        if (x) {
                    $("#sidebar").animate({
                        width: '10%'
                    }).hide()
                    $("#map").animate({
                        width: '89%'
                    });
                    x = 0;
                } else {
                    $("#sidebar").animate({
                        width: '89%'
                    }).show()
                    $("#map").animate({
                        width: '10%'
                    });
                    x = 1;
        }
            }
        </script>
    </head>
<body>
<div id="map"> 
  <input type="button" data-name="show"  onclick="toggle1();" value="Toggle" id="toggle">
</div>
<div id="sidebar">SIDEBAR</div>
</body>
</html>

呼叫方Web资源:

<HTML>
<HEAD>
<BODY>
<INPUT onclick=toggle1() value=Toggle type=button> 
</BODY>
</HTML>

您可以在窗口对象中设置一个变量,并从其他网络资源调用它

webresource_1.html

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="values" />
<script type="text/javascript">
    var mainFunction = function() {
        alert($("#values").val());
    }
    window.top.html1Function = mainFunction;
</script>
</body>

webresource_2.html

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<button id="button"> </button>
<script type="text/javascript">
    $(function() {
        var b = $("#button");
        b.click(function() { window.top.html1Function(); });
    });
</script>
</body>
</html>

最新更新