paul y cho
paul y cho

Reputation: 39

opener.document() won't work on CHROME

Following Script isn't working in CHROME browser, IE is Fine.

I've changed opener.document... to window.opener.document.... but same situation.
It's not closing windows and transfer data to parent page.

function mycoupon() {
    window.open("my_coupon3.jsp?amt=<%=pay_price2%>",
                'coupon_win',
                'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb‌​ars=yes, resizable=no,width=780,height=540');
}

function sel_coupon(c_id, amt) {
    var tot = opener.document.joinform.Org_totalprice.value;
    tot = String(Number(tot) - Number(amt));
    opener.document.joinform.totalprice.value = tot;
    opener.document.joinform.coupon_id.value = c_id;
    opener.document.joinform.all["tot"].innerHTML = maskNum(opener.document.joinform.Org_totalprice.value) + "USD - " + maskNum(amt) + " USD &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='red'>Total : " + maskNum(tot) + " USD</font></b> ";
    opener.cal_payment_money();
    self.close();
}

Upvotes: 0

Views: 2002

Answers (1)

Adi
Adi

Reputation: 5179

Define a global variable and assign a reference to the new window then use it in your sel_coupon() function.

Here's an example:

var new_window_handle;

function mycoupon() {
    new_window_handle = window.open("my_coupon3.jsp?amt=<%=pay_price2%>",
                'coupon_win',
                'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollb‌​ars=yes, resizable=no,width=780,height=540');
}

function sel_coupon(c_id, amt) {
    var tot = new_window_handle.opener.document.joinform.Org_totalprice.value;
    tot = String(Number(tot) - Number(amt));
    new_window_handle.opener.document.joinform.totalprice.value = tot;
    new_window_handle.opener.document.joinform.coupon_id.value = c_id;
    new_window_handle.opener.document.joinform.all["tot"].innerHTML = maskNum(new_window_handle.opener.document.joinform.Org_totalprice.value) + "USD - " + maskNum(amt) + " USD &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='red'>Total : " + maskNum(tot) + " USD</font></b> ";
    new_window_handle.opener.cal_payment_money();
    self.close();
}

In case you're interested in the reason of this behavior, it's because IE assumes that the default window is the most recent one. So that's why when you run the code on IE it will try to find opener in the new window, but other browsers are a bit more strict (which is better in this case)

Upvotes: 1

Related Questions