JavaWeb - JavaScript中Window对象

打开网页

<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(thisurl){
				window.open(thisurl) ;
			}
		</script>
	</head>
	<body onLoad="fun('index.html')">
	</body>
</html>

控制窗口大小

<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(thisurl){
				window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;
			}
		</script>
	</head>
	<body onLoad="fun('index.html')">
	</body>
</html>

Demo

<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(thisurl){
				window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;
			}
		</script>
	</head>
	<body>
		<form action="" method="post" name="myform">
			网址:<select name="url" onChange="fun(this.value)">
					<option value="index.html">index</option>
					<option value="3.html">3</option>
				  </select>
		</form>
	</body>
</html>

确认提示按钮

<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(){
				if(window.confirm("确认删除?")){
					alert("您选择的是'是'!") ;
				} else {
					alert("您选择的是'否'!") ;
				}
			}
		</script>
	</head>
	<body>
		<a href="#" οnclick="fun()">删除邮件</a>
	</body>
</html>

重定向

<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(thisurl){
				window.location = thisurl ;	// 重定向
			}
		</script>
	</head>
	<body>
		网站:<select name="url" onChange="fun(this.value)">
				<option value="#">== 请选择要浏览的站点 ==</option>
				<option value="http://www.baidu.com">百度</option>
				<option value="http://blog.csdn.net/imwangjiping">wjp博客</option>
			  </select>
	</body>
</html>

子窗口调用父窗口(子窗口操作父窗口中的一些对象)

父窗口
<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(thisurl){
				window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;
			}
		</script>
	</head>
	<body>
		<input type="button" value="打开" onClick="fun('3.html')" >
	</body>
</html>
子窗口
<html>
	<head>
		<title></title>
		<script language="javascript">
			function closeWin(){
				window.close() ;		// 关闭窗口
			}
			window.opener.location.reload() ;		// 刷新页面
		</script>
	</head>
	<body>
		<h3><a href="#" οnclick="closeWin()" >关闭</a></h3>	
	
	</body>
</html>

子窗口调用父窗口(子窗口操作父窗口中的一些对象)Demo

父窗口
<html>
	<head>
		<title></title>
		<script language="javascript">
			function fun(thisurl){
				window.open(thisurl, "页面标题", "width=500, height=150, scrollbars=yes, resizeable=no") ;
			}
		</script>
	</head>
	<body>
		<form name="parentform">
			<input type="button" value="选择信息" οnclick="fun('3.html')" >
			<br>选择的结果:<input type="text" name="result">
		</form>
	</body>
</html>
子窗口
<html>
	<head>
		<title></title>
		<script language="javascript">
			function returnValue(){
				var city = document.myform.city.value ;	// 取出当前选择好的信息
				var doc = window.opener.document ;	// 取得父窗口文档
				doc.parentform.result.value = city ;		// 设置新内容
				window.close() ;
			}
		</script>
	</head>
	<body>
		<form name="myform">
			选择:	<select name="city">
						<option value="北京">北京</option>
						<option value="上海">上海</option>
						<option value="深圳">深圳</option>
						<option value="广州">广州</option>
						<option value="天津">天津</option>
					</select>

					<input type="button" value="返回" οnclick="returnValue()">
		</form>
	</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值