Javascript Extjs:防止模式窗口失去焦点
在一个混合rails/sencha应用程序中,我定义了一个类,它在Ext.window.window组件中显示一个小iframe 我希望在按下ESC按钮时关闭此窗口,这是设置Javascript Extjs:防止模式窗口失去焦点,javascript,iframe,extjs,Javascript,Iframe,Extjs,在一个混合rails/sencha应用程序中,我定义了一个类,它在Ext.window.window组件中显示一个小iframe 我希望在按下ESC按钮时关闭此窗口,这是设置模式时的默认行为:true 但是,一旦我在加载的iframe内单击,该绑定将不再工作,即ESC按钮不再关闭窗口。我现在尝试使用模糊和聚焦事件,以便使我的窗口再次获得焦点,从而使窗口保持焦点: Ext.require([ 'Ext.window.*' ]); Ext.define('App.ModalWindow',
模式时的默认行为:true
但是,一旦我在加载的iframe内单击,该绑定将不再工作,即ESC按钮不再关闭窗口。我现在尝试使用模糊和聚焦事件,以便使我的窗口再次获得焦点,从而使窗口保持焦点:
Ext.require([
'Ext.window.*'
]);
Ext.define('App.ModalWindow', {
id: 'modalwindow',
extend: 'Ext.window.Window',
alias: 'widget.modalwindow',
title: 'Component Details',
autoShow: true,
height: 250,
modal: true,
draggable: true,
resizable: false,
width: 550,
layout: 'fit',
header: false,
listeners: {
el: {
blur: {
fn: function() {console.log('loss'); this.focus()},
},
focus: {
fn: function() {
console.log('focus')
},
}
}
},
buttons: [
{
text : 'Close',
handler: function () { this.up('.window').close(); }
}
],
initComponent: function() {
var me = this;
//Close modal window when clicking on mask
me.mon(
Ext.getBody(),
'click',
function(el, e){me.close();},
me,
{ delegate: '.x-mask' }
);
//Add iframe to window
me.items = [{
xtype: "component",
style: {
padding: '10px'
},
autoEl: {
tag: 'iframe',
frameborder: 0,
src: me.detail_link
}
}];
//Call superclass' initComponent
me.callParent(arguments);
}
});
//Add an event luistener to the window, in order to center the modal window when the browser is resized
//first check if modalwindow exists, cause otherwise calling the center() method on a non-existing object
//will stop the event propagation
Ext.EventManager.onWindowResize(function () {
if( Ext.getCmp('modalwindow')) {
Ext.getCmp('modalwindow').center();
}
});
不幸的是,这不起作用。单击iframe会触发模糊,然后再次聚焦,再次单击iframe不会产生相同的效果,最重要的是,ESC按钮仍不会关闭窗口
我做错了什么?即使单击窗口内的iframe,如何使用ESC按钮关闭窗口?您有权访问iframe吗?您可以尝试将侦听器附加到它,但它必须来自iframe内部。iframe有一个完全不同的文档,它不会与父级“共享”事件。您需要侦听实际帧内的事件,然后将调用中继到父文档。