Skip to content

Instantly share code, notes, and snippets.

@varunkumar
Last active December 12, 2015 02:49
Show Gist options
  • Save varunkumar/4701998 to your computer and use it in GitHub Desktop.
Save varunkumar/4701998 to your computer and use it in GitHub Desktop.
Testing the behavior of window.onerror in Firefox with and without crossorigin attribute.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>CORS for static resources</title>
</head>
<body>
<img src="http://slides.varunkumar.me/static/images/may2012.jpg" crossorigin="">
<!-- www.varunkumar.me doesn't set CORS headers -->
<!--script src="http://www.varunkumar.me/static/js/calculator.js"></script>
<script src="http://www.varunkumar.me/static/js/calculator.js" crossorigin=""></script-->
<!-- slides.varunkumar.me sets CORS headers -->
<!--script src="http://slides.varunkumar.me/static/js/calculator.js"></script-->
<script src="http://slides.varunkumar.me/static/js/calculator.js" crossorigin=""></script>
<script>
window.onerror = function(errorMsg, url, lineNumber) {
console.log('[' + url + ':' + lineNumber + '] ' + errorMsg);
return true;
}
Calculator.add(10, 20);
Calculator.add(10, 'One'); // This should throw an exception
dummyObj.dosomething();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment