HTML5+CSS3+JavaScript从入门到精通
作者:王征,李晓波
第十九章 JavaScript窗口的控制和提醒功能
案例
19-01 打开窗口
<!DOCTYPE html>
<!--web19-01-->
<!--
windows对象的属性和方法
-->
<html>
<head>
<meta charset="utf-8" />
<title>打开窗口</title>
<script type="text/javascript">
function customize(form)
{
var address = document.form1.url.value;
var op_tool = (document.form1.tool.checked == true) ? 1 : 0;
var op_loc_box = (document.form1.loc_box.checked == true) ? 1 : 0;
var op_dir = (document.form1.dir.checked == true) ? 1 : 0;
var op_stat = (document.form1.stat.checked == true) ? 1 : 0;
var op_menu = (document.form1.menu.checked == true) ? 1 : 0;
var op_scroll = (document.form1.scroll.checked == true) ? 1 : 0;
var op_resize = (document.form1.resize.checked == true) ? 1 : 0;
var op_wid = document.form1.wid.value;
var op_height = document.form1.height.value;
var option = "toolbar=" + op_tool + ",location=" + op_loc_box + ",directories=" + op_dir + ",status=" + op_stat + ",menubar=" + op_menu + ",scrollbars=" + op_scroll + ",resizeable=" + op_resize + "'width=" + op_wid + ",height=" + op_height;
var win3 = window.open(address, "打开窗口", option);
}
</script>
</head>
<body>
<h3 align="center">打开窗口</h3>
<hr />
<form name="form1" method="post">
<div align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td colspan="4" height="35">
URL:
<input type="text" size="40" name="url" value="http://"
</td>
</tr>
<tr align="center">
<td width="25%" height="25">
<input type="checkbox" name="tool" value="ON" />
:快捷键
</td>
<td width="25%" height="25">
<input type="checkbox" name="loc_box" value="ON" />
:地址栏
</td>
<td width="25%" height="25">
<input type="checkbox" name="dir" value="ON" />
:链 接
</td>
<td width="25%" height="25">
<input type="checkbox" name="stat" value="ON" />
:状态栏
</td>
</tr>
<tr align="center">
<td width="25%" height="25">
<input type="checkbox" name="resize" value="ON" />
:调大小
</td>
<td width="25%" height="25">
<input type="checkbox" name="scroll" value="ON" />
:滚动条
</td>
<td width="25%" height="25">
<input type="checkbox" name="menu" value="ON" />
:菜单
</td>
<td width="25%" height="25"></td>
</tr>
<tr align="center">
<td colspan="2" height="35">
<input type="text" name="wid" size="14" />
:宽
</td>
<td colspan="2" height="35">
<input type="text" name="height" size="14" />
:高
</td>
</tr>
<tr align="center">
<td colspan="4" height="25">
<input type="button" size="10" value="确认" name="button" onclick="customize(this.form)" />
<input type="reset" size="10" value="重填" name="reset" /><!--reset自动把form中的全部重置-->
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
19-02 关闭窗口
<!DOCTYPE html>
<!--web19-02-->
<!--
window.close(): 关闭窗口
resizeTo(iWidth, iHeight): 绝对方式改变窗口大小;
resizeBy(iX, iY): 相对方式改变窗口大小,正数为扩大,负数为缩小;
moveTo(iLeft, iTop): 绝对方式移动窗口;
moveBy(iX, iY): 相对方式移动窗口,正负数绝对移动方向;
-->
<html>
<head>
<meta charset="utf-8" />
<title>关闭窗口</title>
<script type="text/javascript">
function shutwin()
{
window.close();
return;
}
</script>
</head>
<body>
<h3 align="center">关闭窗口</h3>
<hr />
<a href="javascript:shutwin();">关闭本窗口</a>
</body>
</html>
19-03 提示对话框
<!DOCTYPE html>
<!--web19-03-->
<html>
<head>
<meta charset="utf-8" />
<title>提示对话框</title>
<script type="text/javascript">
function show()
{
window.alert("欢迎你登录本网站~");
}
</script>
</head>
<body onload="show()">
<h3 align="center">提示对话框</h3>
<hr />
打开网页时,显示提示对话框
</body>
</html>
19-04 询问对话框
<!DOCTYPE html>
<!--web19-04-->
<html>
<head>
<meta charset="utf-8" />
<title>询问对话框</title>
<script type="text/javascript">
function myq()
{
var myt = window.confirm("请确定要登录本网站吗?");
if (myt) {
window.alert("单击了‘确定’按钮,欢迎登录本网站~");
}
else {
window.alert("单击了'取消'按钮,欢迎下次再来~");
window.close();
}
}
</script>
</head>
<body onload="myq()">
<h3 align="center">询问对话框</h3>
<hr />
询问对话框是利用confirm()方法来创建的
</body>
</html>
19-05 弹出窗口式的密码保护网页
<!DOCTYPE html>
<!--web19-05-->
<html>
<head>
<meta charset="utf-8" />
<title>弹出窗口式的密码保护网页</title>
<script type="text/javascript">
function password()
{
var cishu = 1;
var pass = prompt('请输入密码:', '');
while (cishu < 3)
{
if (!pass)
{
history.go(-1);
}
if (pass == 'qd123456')
{
window.alert("密码正确,可以成功登录");
break;
}
var pass = prompt("密码错误!请重新输入,还有" + (3 - cishu) + "次机会:")
cishu++;
}
if (pass != "qd123456" & cishu == 3) //只有一个&
{
window.alert("登录失败!");
window.close();
}
}
</script>
</head>
<body onload="password()">
<h3 align="center">弹出窗口式的密码保护网页</h3>
<hr />
弹出窗口式的密码保护网页
</body>
</html>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。