gpt4 book ai didi

javascript - 当我尝试使用 parent.rifiutaSingolo() 从对话框执行定义到父页面的功能时,为什么会收到此错误消息?

转载 作者:太空宇宙 更新时间:2023-11-03 17:32:45 24 4
gpt4 key购买 nike

我在尝试从定义到打开此对话框的父页面中的对话框执行 JavaScript 函数时遇到以下问题。

所以我有这种情况:

我有一个名为 autorizzaFattura2parent page 页面,它是通过此 JavaScript 打开对话框的页面(当用户单击链接时,对话框打开):

function openDialog2(pagina,larghezza,lunghezza,tipo) {

//alert("INTO openDialog2(), pagina: " + pagina, " larghezza: " + larghezza + " lunghezza: " + lunghezza + " tipo: " + tipo);

larghezza = '950px';
lunghezza = '470px';
lunghezza2 = '530px';
if (tipo == 3) {
larghezza = '950px';
lunghezza = '470px';
lunghezza2 = '530px';
}

if (tipo == 9) {
larghezza = '950px';
lunghezza = '470px';
lunghezza2 = '530px';
}
unitaLargo = larghezza.substring(larghezza.length - 2, larghezza.length)
unitaLungo = lunghezza.substring(lunghezza.length - 2, lunghezza.length)

var puntiLarghezza = 0;
var puntiLunghezza = 0;

if (unitaLargo != "px") {
//per default è in percentuale
Wlargo = (screen.width * larghezza) / 100;
puntiLarghezza = Wlargo;
Wlargo = Wlargo + "px";
} else {
Wlargo = larghezza
puntiLarghezza = larghezza.substring(0, larghezza.length - 2);
}

if (unitaLungo != "px") {
//per default è in percentuale
Wlungo = (screen.height * lunghezza) / 100;
puntiLunghezza = Wlungo;
Wlungo = Wlungo + "px";
} else {
Wlungo = lunghezza
puntiLunghezza = lunghezza.substring(0, lunghezza.length - 2);
}

var l = (screen.width / 2) - (puntiLarghezza / 2);
var t = (screen.height / 2) - (puntiLunghezza / 2);

DialParam = 'width=' + Wlargo + ',height=' + Wlungo + ',toolbar=no,directories=no,';
DialParam = DialParam + 'toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=yes,resizable=no';

//alert("pagina: " + pagina);
pag_aperta = window.open(pagina, 'popUp_', DialParam);
pag_aperta.moveTo(l, t);
pag_aperta.focus();
}

因此,如您所见,弹出窗口是由 window.open() 语句打开的,这个:

pag_aperta = window.open(pagina, 'popUp_', DialParam);

好的,在这个父页面 (autorizzaFattura2) 中也定义了 rifiutaSingolo() JavaScript 函数,这个:

function rifiutaSingolo() {

alert("Into rifiutaSingolo()");

chiudi();
$('#myRejectNote').css("visibility", "visible");
$('#rifiutaTable').css("visibility", "visible");
$("#dialogReject").dialog("open");
document.getElementById('myRejectNote').focus();
}

好的,在 openDialog2() 函数打开的对话框中有这个按钮,单击它必须执行父页面中定义的 rifiutaSingolo() 函数:

<input style="color: #FFFFFF; font: bold 10px tahoma,arial,helvetica,sans-serif" class="bottone" readonly="readonly" type="button" value="Rifiuta" onclick="parent.rifiutaSingolo()">

我尝试使用 parent 来做到这一点,方法是:onclick="parent.rifiutaSingolo()" 但它不起作用而且 rifiutaSingolo() 函数未执行,在 FireBug 控制台中我收到此错误消息(当我单击按钮时):

TypeError: parent.rifiutaSingolo is not a function

为什么?我错过了什么?如何解决此问题并正确执行父页面中定义的 rifiutaSingolo() 函数?

最佳答案

自己解决。

问题是我的对话框不是真正的对话框,它是由 window.open 创建和显示的

pag_aperta = window.open(pagina, 'popUp_', DialParam);

因此,要执行父页面中定义的 rifiutaSingolo(),我不能使用它:

onclick="parent.rifiutaSingolo()"

因为它与对话框有关,但我必须使用它:

onclick="window.opener.rifiutaSingolo()"

与窗口相关

关于javascript - 当我尝试使用 parent.rifiutaSingolo() 从对话框执行定义到父页面的功能时,为什么会收到此错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30255945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com