Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
think2011 committed Oct 27, 2015
1 parent deb779e commit c19c7ae
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions js.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,38 @@ window.px2rem = function(v) {

window.dpr = dpr;
window.rem = rem;
```

- 获取js所在路径
```js
function getJsDir (src) {
var script = null;

if (src) {
script = [].filter.call(document.scripts, function (v) {
return v.src.indexOf(src) !== -1;
})[0];
} else {
script = document.scripts[document.scripts.length - 1];
}

return script ? script.src.substr(0, script.src.lastIndexOf('/')) : script;
}
```

- 从全局捕获错误
```js
window.onerror = function (errMsg, scriptURI, lineNumber, columnNumber, errorObj) {
setTimeout(function () {
var rst = {
"错误信息:": errMsg,
"出错文件:": scriptURI,
"出错行号:": lineNumber,
"出错列号:": columnNumber,
"错误详情:": errorObj
};

alert(JSON.stringify(rst, null, 10));
});
};
```

0 comments on commit c19c7ae

Please sign in to comment.