弹出提示框的 try…catch 语句
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- var txt = "";
- function message() {
- try {
- adddlert("Welcome guest!");
- }
- catch(err) {
- txt = "此页面出错。\n\n";
- txt += "单击“确定”继续查看此页面,\n";
- txt += "或取消以返回主页。\n\n";
- if(!confirm(txt)) {
- document.location.href = "http://www.yousite.com/";
- }
- }
- }
- </script>
- </head>
- <body>
- <input type="button" value="查看消息" onclick="message()" />
- </body>
- </html>