Javascript 使用Internet Explorer中的window.opener在窗口之间传递变量
我有两扇窗户;其中一个是使用函数Javascript 使用Internet Explorer中的window.opener在窗口之间传递变量,javascript,jquery,internet-explorer,window.open,window.opener,Javascript,Jquery,Internet Explorer,Window.open,Window.opener,我有两扇窗户;其中一个是使用函数窗口打开的。打开(“URL”,“参数”)。我的问题是,我想将元素从子窗口发送到父窗口,这在除Internet Explorer(目前使用IE11)之外的所有浏览器中都可以正常工作 我想找到一个解决方案,因为它需要在Internet Explorer上工作 我使用的代码是用jQuery编写的,如下所示: //Inicializating document and events var x=$(document); x.ready(inicializarDocumen
窗口打开的。打开(“URL”,“参数”)
。我的问题是,我想将元素从子窗口发送到父窗口,这在除Internet Explorer(目前使用IE11)之外的所有浏览器中都可以正常工作
我想找到一个解决方案,因为它需要在Internet Explorer上工作
我使用的代码是用jQuery编写的,如下所示:
//Inicializating document and events
var x=$(document);
x.ready(inicializarDocumento);
function inicializarDocumento(){
var x=$("#boAceptar");
//When i click in my button it executes the function pasarDatos
x.click(pasarDatos);
}
function pasarDatos(){
//I get the reference of the windows father
var doc=window.opener.document;
var x=window.opener.$("#seleccionDireccionId");
var form=$("form[name='foconfirmar']");
//I execute the next code when i submit the form
form.submit(function (event){
var listadoid=$("#listadoid option:selected");
var tipoVia=$("#idTipoVia");
var km=$("#idkm");
var piso=$("#idPiso");
var puerta=$("#idPuerta");
var urbanizacion=$("#idUrbanizacion");
var bloque=$("#idBloque");
var escalera=$("#idEscalera");
var observaciones=$("#idObservaciones");
if (listadoid.text()==""){
alert("Debe seleccionar una dirección de las disponibles");
}else{
var o = new Option(listadoid.text()+", "+tipoVia.val()+", "+km.val()+", "+piso.val()+", "+puerta.val()+", "+urbanizacion.val()+", "+bloque.val()+", "+escalera.val()+", "+observaciones.val(), listadoid.val());
$(o).html(listadoid.text()+", "+tipoVia.val()+", "+km.val()+", "+piso.val()+", "+puerta.val()+", "+urbanizacion.val()+", "+bloque.val()+", "+escalera.val()+", "+observaciones.val());
x.append(o);
}
event.preventDefault();
event.stopImmediatePropagation();
});
self.close();
}
当你说“不行”时,到底发生了什么?调试控制台中是否显示错误?而不是此
var x=window.opener.$(“#seleccionDireccionId”)代码>,我建议试试这个:varx=$(“#seleccionDireccionId”,doc)代码>我刚刚对我的代码进行了调试,首先在“x.append(o)”行中给了我一个语法错误,然后它给了我另一个错误,上面写着“exception not controled”,我猜第二个错误只是第一个错误的连续结果。我不得不说,我也尝试过你的建议,但仍然是一样的,但是我猜当你在错误文档的上下文中创建DOM元素时,你不能使用jQuery方法,因为jQuery将为错误的文档创建内容(内部使用document.createElement()
)使用错误的文档
对象。