Good day all, I'm struck on this easy problem, I need your advice once more:
大家好,我对这个简单的问题很感兴趣,我再次需要你的建议:
I'm editing a EXTjs application (which I didn't do). in this application, there is at some point an iframe, that call an external html file, defined:
我正在编辑EXTjs应用程序(我没有这么做)。在这个应用程序中,有一个iframe,它调用外部html文件,定义如下:
items: [{
xtype: "component",
id: "dasboardM",
autoEl: {
tag: "iframe",
width: '100%',
height: '95%',
src: "/resources/extendpanel/dashboard.html"
}
}]
I need to call functions defined in the view controller FROM the iframe, there will be several function to be called, and for now I've setted up a simple test case, so I've created the controller for the view file that has the iframe like the following:
我需要从iframe中调用视图控制器中定义的函数,有几个函数需要调用,目前我已经设置了一个简单的测试用例,因此我为具有iframe的视图文件创建了控制器,如下所示:
Ext.define('Dor3.view.merch.MerchController', {
extend: 'Ext.app.ViewController',
alias: 'controller.merch',
...
onIframeCall : function(){
console.log("fromIframe!");
}
well, in the iframe I have this code, which I have found on the sencha forums, an old thread:
在iframe中,我有这个代码,我在sencha论坛上找到了,一个旧的线程:
$(".iframeToExt").click(function(){
var myParent = window.parent;
var controller = myParent.window.Dor3.app.getController('Dor3.view.merch.MerchController');
controller.onIframeCall();
});
this is actually not working, well, is there a way to call that function from the iframe?
这实际上不起作用,有办法从iframe调用这个函数吗?
thanks in advance.
提前谢谢。
2 个解决方案
#1
1
You can send a message from an iframe
to the parent window and write code that responds to it. For example from an iframe
execute:
您可以从iframe发送消息到父窗口,并编写响应该窗口的代码。例如从iframe执行:
window.parent.postMessage('message', '*');
And in the MerchController
you can implement onmessage
like this:
在商业控制器中,你可以实现onmessage,像这样:
window.onmessage = function(ev){
if (ev.data == 'message') {
controller.onIframeCall();
}
};
Note that instead of 'message'
you can pass an object if you need to. Check API info for postMessage.
注意,如果需要,可以传递一个对象,而不是“message”。查看API信息以获取postMessage。
#2
0
You can simply use (appname).app.getController(controller's full name) This will return you controller object & you can call that controller's method.
你可以简单地使用(appname).app。getController(控制器的全名)返回控制器对象,你可以调用控制器的方法。
#1
1
You can send a message from an iframe
to the parent window and write code that responds to it. For example from an iframe
execute:
您可以从iframe发送消息到父窗口,并编写响应该窗口的代码。例如从iframe执行:
window.parent.postMessage('message', '*');
And in the MerchController
you can implement onmessage
like this:
在商业控制器中,你可以实现onmessage,像这样:
window.onmessage = function(ev){
if (ev.data == 'message') {
controller.onIframeCall();
}
};
Note that instead of 'message'
you can pass an object if you need to. Check API info for postMessage.
注意,如果需要,可以传递一个对象,而不是“message”。查看API信息以获取postMessage。
#2
0
You can simply use (appname).app.getController(controller's full name) This will return you controller object & you can call that controller's method.
你可以简单地使用(appname).app。getController(控制器的全名)返回控制器对象,你可以调用控制器的方法。