0

我遇到了 IE 问题,当我使用 javascript 打开子窗口并在子窗口上附加 onerror 事件时,我没有在子窗口的 OnLoad 中捕获 JS 错误。下面的代码在 FF 中运行良好。这是代码示例:

父页面

<html>
<head>
<script>
function openpage()
{
    console.log('opening');
    var w = window.open('demo2.html', '_blank');
    //without setTimeout onerror is not working
    setTimeout(function(){w.onerror = function(msg, file, line) { alert(msg); };}, 3000)
    //w.onerror = function(msg, file, line) { alert(msg); };
}
</script>
</head>
    <body>
        <input type="button" onclick="openpage()" />
    </body>
</html>

子页面代码(demo2.html):

<html>
<head>
<script>
//function with error
function fun(var1,var2){aler(var1);}
</script>
</head>
    <body onload="fun(2,3)">
        <input type="button" onclick="fun(2,3)" />
    </body>
</html>

如果上述方式无效/不正确,请提出一种捕获子页面上生成的 JS 错误的方法。

谢谢, 潘卡伊

4

0 回答 0