Created
November 27, 2020 10:12
-
-
Save wizardnet972/c25e697423697738a97186d9d45ab672 to your computer and use it in GitHub Desktop.
catch error in iframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index.html: | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Document</title> | |
</head> | |
<body> | |
<iframe src="./iframe.html"></iframe> | |
<script> | |
var w = document.getElementsByTagName("iframe")[0].contentWindow; | |
w.addEventListener('error', function() { | |
console.log('in error'); | |
}); | |
</script> | |
</body> | |
</html> | |
iframe.html: | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Document</title> | |
</head> | |
<body> | |
im iframe!!! | |
<script> | |
setTimeout(function () { | |
throw "error"; | |
}, 5 * 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment