如何从其他网络资源(html)调用网络资源(html)功能?
问题描述:
我正在使用Dynamics CRM,其中我们在同一表单上有两个不同的Web资源。现在,当我试图从一个Web资源调用Java脚本函数到另一个Web资源时,它会产生以下错误。如何从其他网络资源(html)调用网络资源(html)功能?
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
叫它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>