Tag Archive error

Byphunsanit

Javascript Debugging

Code สั้นๆ ไว้แสดง message เวลา javascript มี error หรือจะดัดแปลงให้ส่ง error กลับไปที่ server ผ่าน ajax ก็ได้ครับ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>javascript onerror</title>
</head>
 
<body>
<script>
window.onerror = function (msg, url, line) {
    str = "Message :\t\t"+msg+"\nUrl :\t\t\t"+url+"\nLine number :\t"+line;
    alert(str);
}
 
/* ตัวอย่างไปเรียก function ที่ไม่มีจริง */
noBody();
</script>
</body>
</html>

เรื่องที่เกี่ยวข้อง