【问题标题】:Uncaught TypeError in CHROMECHROME 中未捕获的 TypeError
【发布时间】:2012-06-27 22:15:18
【问题描述】:

我之前问过同样的问题。但它在 CHROME 上仍然有错误,但它在 IE 上运行良好。 父 html 调用 mycoupon3.jsp 作为弹出窗口,如果选择了弹出窗口中的某一行,它会将 INNERHTML 发送到父 html。

问题是,弹出窗口中的数据未处理到父 html。在 chrome 调试工具上说 Uncaught TypeError: Cannot read property 'tot' of undefined on "opener.document.joinform.all["tot"].innerHTML"。弹出窗口也不会 self.close。

我认为 all["tot"] 与 chrome 不兼容。 于是改成了 opener.document.joinform.getelementbyid["tot"].innerHTML,但是没有运气。

这是代码。

<parent html>

 <td id="tot" class="text_orange"><%=NumberFormat.getInstance().format(cmbean.getTotal())%> USD</td>

 <a href="javascript: mycoupon()"><img src="/images/main/mycoupon_btn.gif" border="0"></a>


<script>

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,scrollbars=yes, resizable=no,width=780,height=540'); 
} 

</script>   

<my_coupon3.jsp> * POPUP window

<script>
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();
}
</script>

<a href="javascript: sel_coupon('BGG30055901', '3000')"> Apply This coupon</a>

【问题讨论】:

    标签: google-chrome popup


    【解决方案1】:

    getElementById 不是一个对象,而是一个函数。称呼它:

    document.getElementById('tot')
    

    请注意,您必须将其应用于document;个别元素没有getElementById。这也是使用.all 的问题;虽然 Chrome 支持 all 是为了与为 Internet Explorer 设计的页面兼容,但它只支持 document 的属性。

    【讨论】:

    • 谢谢。但是 chrome 调试器说 / Uncaught TypeError: Object [object HTMLFormElement] has no method 'getElementById'
    • @paulycho:当我说document.getElementById 时,我的意思是opener.document.getElementById,而不是opener.document.joinform.getElementById。 (请务必阅读答案的其余部分,而不仅仅是第一句话。)
    • 谢谢。我解决了这个问题。我给“getElementById”写了错误的大写字母。 Chrome 区分大小写..
    • 所有浏览器都区分大小写,仅供参考:)
    猜你喜欢
    • 2013-03-17
    • 2013-07-31
    • 2012-03-29
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多