[英]How can I catch an exception thrown from inside an iframe?
如何捕獲iframe中引發的異常?
這是我的代碼:
家長:
iframe = document.createElement("iframe");
iframe.src = "../a.aspx";
iframe.style.display = "none";
document.body.appendChild(iframe);
以及a.aspx中的代碼:
protected void Page_Load(object sender, EventArgs e)
{
GenerateKey();
//This function throws an exception, and I want to catch it in the parent window (javascript)
}
我想在打開iframe並顯示警告框的頁面中捕獲異常。 我嘗試了iframe.contentWindow.onerror,但是沒有用。
謝謝您的幫助,
英巴爾。
跨原點可能會禁止您控制iframe。 在iframe頁面中,您可以捕獲其異常並調用父函數來顯示它。
try{
//something
}catch(e){
window.top.some_public_function(e);
//window.parent.some_public_function(e) is also work
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.