捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg:错误描述,比如:a is not definedurl:出错脚本所在的urllineNumber:出错脚本的行数
本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>DEMO</title> | |
| <script type="text/javascript" src="simple_javascript_templating.js"></script> | |
| </head> | |
| <body> | |
| <table id="table_1"> | |
| </table> | |
| <script type="text/html" id="tmpl_1"> |
| /** | |
| * jsDump | |
| * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com | |
| * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php) | |
| * Date: 5/15/2008 | |
| * @projectDescription Advanced and extensible data dumping for Javascript. | |
| * @version 1.0.0 | |
| * @author Ariel Flesler | |
| * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} | |
| */ |
| /* | |
| * Javascript Diff Algorithm | |
| * By John Resig (http://ejohn.org/) | |
| * Modified by Chu Alan "sprite" | |
| * | |
| * Released under the MIT license. | |
| * | |
| * More Info: | |
| * http://ejohn.org/projects/javascript-diff-algorithm/ | |
| * |
| // Domain Public by Eric Wendelin http://eriwen.com/ (2008) | |
| // Luke Smith http://lucassmith.name/ (2008) | |
| // Loic Dachary <loic@dachary.org> (2008) | |
| // Johan Euphrosine <proppy@aminche.com> (2008) | |
| // Oyvind Sean Kinsey http://kinsey.no/blog (2010) | |
| // Victor Homyakov <victor-homyakov@users.sourceforge.net> (2010) | |
| /*global module, exports, define, ActiveXObject*/ | |
| (function(global, factory) { | |
| if (typeof exports === 'object') { | |
| // Node |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
| <title>FishEye</title> | |
| <style> | |
| html { |
| macro varr { | |
| rule {$name:ident(,)... = $val:expr(,)...} => { | |
| $(var $name = $val;)... | |
| } | |
| } | |
| varr a, b, c = 1, 2, 3 |
| /* | |
| Copyright 2013, KISSY UI Library v1.40dev | |
| MIT Licensed | |
| build time: Aug 13 19:05 | |
| */ | |
| /** | |
| * @ignore | |
| * A seed where KISSY grows up from, KISS Yeah ! | |
| * @author https://github.com/kissyteam?tab=members | |
| */ |
| /** | |
| * @class bezier | |
| */ | |
| KISSY.add('khc/lib/bezier', function(S) { | |
| var TOTAL_SIMPSON_STEP = 100; | |
| /** | |
| * @class bezier | |
| */ |
| /** | |
| * @object -- game resource | |
| */ | |
| KISSY.add('khc/mods/game/carnival/gameResource', function(S) { | |
| var BASE_PATH = '../src/image/game/carnival/'; | |
| var X_SIZE = 10; | |
| var Y_SIZE = 10; | |
| var carnivalCfg = [{ | |
| name: 'map', |
捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg:错误描述,比如:a is not definedurl:出错脚本所在的urllineNumber:出错脚本的行数本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。