Code สั้นๆ ไว้แสดง message เวลา javascript มี error หรือจะดัดแปลงให้ส่ง error กลับไปที่ server ผ่าน ajax ก็ได้ครับ
[sourcecode language=”html”]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>javascript onerror</title>
</head>
<body>
<script>
window.onerror = function (msg, url, line) {
str = "Message :tt"+msg+"nUrl :ttt"+url+"nLine number :t"+line;
alert(str);
}
/* ตัวอย่างไปเรียก function ที่ไม่มีจริง */
noBody();
</script>
</body>
</html>
[/sourcecode]เรื่องที่เกี่ยวข้อง
About the author