javascript
JavaScript onerror事件
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
1 onerror事件描述
使用onerror事件是一種老式的標(biāo)準(zhǔn)的在網(wǎng)頁(yè)中捕獲Javascript錯(cuò)誤的方法
2 何時(shí)產(chǎn)生onerror事件
只要頁(yè)面中出現(xiàn)腳本錯(cuò)誤,就會(huì)產(chǎn)生onerror事件
3 如何使用onerror事件
利用onerror事件,就必須創(chuàng)建一個(gè)錯(cuò)誤的函數(shù)。你可以把這函數(shù)叫作onerror事件處理器。這個(gè)事件處理器使用三個(gè)參數(shù)來調(diào)用:msg(錯(cuò)誤消息), url(發(fā)生錯(cuò)誤的頁(yè)面的url), line(發(fā)生錯(cuò)誤的代碼行)
4 語(yǔ)法
onerror = handleErr
function handleErr(msg, url, line){
//Handle the error here
return true or false
}
5 解釋
瀏覽器是否現(xiàn)實(shí)標(biāo)準(zhǔn)的錯(cuò)誤消息,取決于onerror的返回值,如果返回值為false,則在控制臺(tái)中顯示錯(cuò)誤消息,反之則不會(huì)
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>
轉(zhuǎn)載于:https://my.oschina.net/syc2013/blog/345776
總結(jié)
以上是生活随笔為你收集整理的JavaScript onerror事件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux sed命令使用
- 下一篇: (转)pipe row的用法, Orac