【发布时间】:2012-07-27 06:55:48
【问题描述】:
如何捕获 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,但没有成功。
感谢您的帮助,
英巴尔。
【问题讨论】:
-
纠正异常错误 - 不要试图找到解决方案来捕获它。
-
@Aristos - 我想向用户显示错误,但我想在父页面内执行此操作。这是“更正”。
-
当您遇到异常时(捕获它):呈现在父级上显示消息的 javascript 代码。没有别的办法,当你的 iframe 抛出异常时,父页面没有运行。
-
我在 iframe 服务器端试过这个: Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "parent.test();", true);但它没有用。你有什么建议吗?非常感谢!
标签: javascript asp.net iframe frameset-iframe