带有确认框的 try…catch 语句
- <html>
- <head>
- <script type="text/javascript">
- var txt=""
- function message()
- {
- try
- {
- adddlert("Welcome guest!")
- }
- catch(err)
- {
- txt="本页中存在错误。\n\n"
- txt+="点击“确定”继续查看本页,\n"
- txt+="点击“取消”返回首页。\n\n"
- if(!confirm(txt))
- {
- document.location.href="/index.html"
- }
- }
- }
- </script>
- </head>
- <body>
- <input type="button" value="查看消息" onclick="message()" />
- </body>
- </html>