实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script>
5
var txt="";
6
function message()
7
{
8
try
9
  {
10
  adddlert("Welcome guest!");
11
  }
12
catch(err)
13
  {
14
  txt="There was an error on this page.\n\n";
15
  txt+="Click OK to continue viewing this page,\n";
16
  txt+="or Cancel to return to the home page.\n\n";
17
  if(!confirm(txt))
18
    {
19
    document.location.href="https://www.w3schools.com/";
20
    }
21
  }
22
}
23
</script>
24
</head>
25
26
<body>
27
<input type="button" value="View message" onclick="message()" />
28
</body>
29
30
</html>
31