对document.write(),confirm(),prompt(),window.open(),alert等简单交互的应用集合写了以下小程序,该程序实现的功能是在html中插入一个交互按钮,用户点击该按钮后,弹出对话框,询问用户是否打开新的网页,默认打开www.baidu.com,打开的网页设置一定的格式,代码如下:
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
function openWindow(){
var openweb=confirm("是否在要打开新的网页");
if (openweb==true){
var weburl=prompt("请输入要打开的网址","http://www.baidu.com");
window.open(weburl,'_blank','width=400,height=300');
}
else
{
alert(“谢谢,再见!”)}}
</script>
</head>
<body>
<input type="button" value="点击在新的窗口打开网站" onclick="openWindow()" />
</body>
</html>