I hope this is the right forum for this question, previously I posted at wrong place
My issue is when I open a child window using javascript and attach onerror event on child window I am not getting JS error caught in OnLoad of child window.
here is code example:
Demo Page 1 code:
<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>
Demo Page 2 code (demo2.html):
<html>
< head>
< script>
//function with error
function fun(var1,var2){aler(var1);}
< /script>
< meta charset="UTF-8">
< /head>
<body onload="fun(2,3)">
< input type="button" onclick="fun(2,3)" />
< /body>
< /html>
Please suggest a way to capture the JS error generated on child page If above way is not valid/correct.
Thanks,
Pankaj