強制網頁不要出現JAVAScript的錯誤顯示

try this in <head>
<script>
οnerrοr=function skip_er(){}
</script>


===================================================
回應者: 陳 yatai@ms21.hinet.net

這是我在網路上看到的,覺的不錯,提供大家參考
偵測錯誤:

testerror.htm :

<html>
<head>
<title>Error Test (WebFX)</title>
<!-- end WebFX Layout Includes -->
<script type="text/javascript" src="error.js"></script>
<script type="text/javascript">
thisShouldCauseAnError++;
</script>
<script type="text/javascript">
alert("This as well"):
</script>
<script type="text/javascript">
alert("And this: " + @fo@));
</script>

</head>
<body>

<table style="width: 100%; height: 100%">
<tr><td valign="top" align="left">
<p style="width: 100%">This page should result in three errors</p>
</td></tr>
<tr><td valign="bottom" align="right">
<p style="width: 100%"><a href="#" οnclick="window.close(); return false">Close</a></p>
</td></tr>
</table>

</body>
</html>

error.js :

document._error_messages = new Array();
var w;

function doError(msg,url,ln) {
var _error_obj = {msg : msg, url : url, ln : ln};

document._error_messages[document._error_messages.length] = _error_obj;

str = ""
str += "<title>Error Dialogue (WebFX)</title>"
str += "<script>window.οnlοad=new Function('showError()');"
str += 'var nr=0;'
str += 'function next() {'
str += ' nr=Math.min(window.opener.document._error_messages.length-1,nr+1);'
str += ' showError();'
str += '}'
str += 'function previous() {'
str += ' nr=Math.max(0,nr-1);'
str += ' showError();'
str += '}'
str += 'function showError() {'
str += ' errorArray = window.opener.document._error_messages;'
str += ' if (errorArray.length != 0 && nr >= 0 && nr < errorArray.length) {'
str += ' url.innerText = errorArray[nr].url;'
str += ' msg.innerText = errorArray[nr].msg;'
str += ' ln.innerText = errorArray[nr].ln;'
str += ' }'
str += '}</script>'
str += "<style>"
str += "body {background: white; color: black; border: 10 solid navy; font-family: tahoma, arial, helvitica; font-size: 12px; margin: 0;}"
str += "p {font-family: tahoma, arial, helvitica; font-size: 12px; margin-left: 10px; margin-right: 10px;}"
str += "h1 {font-family: arial black; font-style: italic; margin-bottom: -15; margin-left: 10; color:navy}"
str += "button {margin: 0; border: 1 solid #dddddd; background: #eeeeee; color: black; font-family: tahoma, arial; width: 100}"
str += "a {color: navy;}"
str += "a:hover {color: blue;}"
str += "</style>"
str += '<body scroll="no">'
str += "<h1>Oops!</h1>"
str += '<p>An error ocurred in the file <strong id="url"></strong>This might prevent the page from working correctly.</p>'
str += '<p style="margin-bottom: 5;">Please report this to <a href="/contact.html#emil">EAE</a> or <a href="/contact.html#erik">Erik</a></p>'
str += '<table style="width: 100%;" cellspacing=0 cellpadding=10><tr><td>'
str += '<button οnclick=/'if (infoArea.style.display!="block") {infoArea.style.display = "block";window.resizeTo(400,308);this.innerText="Hide Error";}else {infoArea.style.display="none";window.resizeTo(400,219);this.innerText="Show Error";}/''
str += 'οnmοuseοver="this.style.borderColor=/'black/'" οnmοuseοut="this.style.borderColor=/'#dddddd/'">Show Error</button>'
str += '</td><td align="RIGHT"><button οnclick="window.close()" οnmοuseοver="this.style.borderColor=/'black/'" οnmοuseοut="this.style.borderColor=/'#dddddd/'">Ok</button>'
str += '</td></tr></table>'
str += '<div id="infoArea" style="display: none;">'
str += '<div id="info" style="background: #eeeeee; margin: 10; margin-bottom: 0; border: 1 solid #dddddd;">'
str += '<table>'
str += '<tr><td><p>Message:</p></td><td><p id="msg"></p></td></tr>'
str += '<tr><td><p>Line:</p></td><td><p id="ln"></p></td></tr>'
str += '</table>'
str += '</div>'
str += '<table style="width: 100%;" cellspacing=0 cellpadding=10><tr><td>'
str += '<button οnclick="previous()" οnmοuseοver="this.style.borderColor=/'black/'" οnmοuseοut="this.style.borderColor=/'#dddddd/'">Previous</button>'
str += '</td><td align=right><button οnclick="next()" οnmοuseοver="this.style.borderColor=/'black/'" οnmοuseοut="this.style.borderColor=/'#dddddd/'">Next</button>'
str += '</td></tr></table>'
str += '</div>'
str += '</body>'

if (!w || w.closed) {
w = window.open("","_webxf_error_win","width=390,height=190");
var d = w.document;
d.open();
d.write(str);
d.close();
w.focus();
}
return true;
}

window.onerror = doError
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值