情景:android5.1、开发工具 WeX5,通过iframe引入了网站页面。
需求:在iframe引入的页面js中调用X5 通过require引入的js的函数;
实现方案:
1.在X5首页加入如下代码:在iframe同级的代码中添加div 加id、加bind-click; bind-click对应的函数写在X5首页的对应的js中。
<div xmlns="http://www.w3.org/1999/xhtml" xid="window" class="window" component="$UI/system/components/justep/window/window" design="device:m;">
<div id="content_main" bind-click="checkUpgrade" component="$UI/system/components/justep/model/model" xid="model"/>
<iframe id="content_frame" src="./sourse/index.html#/login" style="width:100%;height:100%;"></iframe>
</div>
bind-click对应的函数
Model.prototype.checkUpgrade = function(){
//do something
};
--目前已经可以在iframe对应的页面js中用top.window.document.getElementById("content_main").click();的方式调用bind-click对应的函数了。
2.进阶--在checkUpgrade中调用通过require方式导入的js文件中的函数:
require引入的文件定义要求:
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
return {
loadDataFromFile : function(url,objData,operation) {
if (operation) { objData.clear();}
$.ajaxSettings.async = false;
$.getJSON(url, function(data) {
objData.loadData(data);
});
}
}
});
调用示例:
Model.prototype.checkUpgrade = function(){
allData.loadDataFromFile(url,event.source,true);
};
--over--仅供参考,欢迎交流