javascript
JavaScript onerror事件
2019獨角獸企業重金招聘Python工程師標準>>>
1 onerror事件描述
使用onerror事件是一種老式的標準的在網頁中捕獲Javascript錯誤的方法
2 何時產生onerror事件
只要頁面中出現腳本錯誤,就會產生onerror事件
3 如何使用onerror事件
利用onerror事件,就必須創建一個錯誤的函數。你可以把這函數叫作onerror事件處理器。這個事件處理器使用三個參數來調用:msg(錯誤消息), url(發生錯誤的頁面的url), line(發生錯誤的代碼行)
4 語法
onerror = handleErr
function handleErr(msg, url, line){
//Handle the error here
return true or false
}
5 解釋
瀏覽器是否現實標準的錯誤消息,取決于onerror的返回值,如果返回值為false,則在控制臺中顯示錯誤消息,反之則不會
6示例
<html>
<head>
<script>
onerror = handleErr
var txt = ''
function handleErr(msg, url, line){
txt = "There was an error on this page. \n\n";
txt += 'Error: '+msg+"\n";
txt += "URL: "+url+"\n";
txt += "Line: "+line+"\n";
txt += "Click OK to continue.\n\n"
return true
}
function message(){
addlert("Welcome guest!")
}
</scrip>
</head>
<body>
<input type="button" value="View message" οnclick="message()">
</body>
</html>
轉載于:https://my.oschina.net/syc2013/blog/345776
總結
以上是生活随笔為你收集整理的JavaScript onerror事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux sed命令使用
- 下一篇: (转)pipe row的用法, Orac