I have multiframe application, where each form opens in separated frame and can use some JS API from parent window. API can throw an exception (error), but I can’t catch it in iframe. It is reproduced in IE8 only. I’ve checked it in IE8/IE9 and Chrome. e.g.:
test.html
<html>
<head>
<script language="JavaScript" type="text/javascript">
var g_fn = {};
function onLoad() {
g_fn.thrown_error = function() {
throw new Error("Main window: error");
return 1;
}
window.g_fn = g_fn;
}
function window_do() {
try {
g_fn.thrown_error();
} catch (err) {
alert("Error catched!");
}
}
</script>
</head>
<body onload="onLoad();">
<input type="button" value="do smth in window" onclick="window_do();"/>
<iframe src="/iframe.html" />
</body>
</html>
iframe.html
<html>
<head>
<script language="JavaScript" type="text/javascript">
var g_fn;
function onLoad() {
g_fn = window.parent.g_fn;
}
function iframe_do() {
try {
g_fn.thrown_error();
} catch (err) {
alert("Error catched!");
}
}
</script>
</head>
<body onload="onLoad();">
<input type="button" value="do smth in iframe" onclick="iframe_do();"/>
</body>
</html>
Is that an IE-bug? Any workarounds?
Try this:
Or this, if there are
iframes insideiframes: