Javascript 如何捕获从iframe内部抛出的异常?

Javascript 如何捕获从iframe内部抛出的异常?,javascript,asp.net,iframe,frameset-iframe,Javascript,Asp.net,Iframe,Frameset 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 sen

如何捕获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,但没有成功

谢谢你的帮助


Inbal.

交叉原点可能不允许您控制iframe。 在iframe页面中,您可以捕获其异常并调用父函数来显示它

try{
//something
}catch(e){
   window.top.some_public_function(e);
   //window.parent.some_public_function(e) is also work
}

更正异常错误-不要试图找到解决方案来捕获它。@Aristos-我想向用户显示一个错误,但我想在父页面中显示。这就是“更正”。当您有异常(捕获它)时:呈现一个javascript代码,在父级上显示一条消息。没有其他方法,当您的iframe抛出异常时,父页面未运行。我在iframe服务器端尝试了此方法:page.ClientScript.RegisterStartupScript(this.GetType(),“Error”,“parent.test();”,true);但它不起作用。你有什么建议吗?谢谢!如何处理异步抛出的异常?@AlexPashkov你能更具体一点吗?例子?最好只是提出一个问题