X5 环境通过iframe引入的页面调用X5函数

情景: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--仅供参考,欢迎交流

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值