1. 程式人生 > >window物件的open和close方法

window物件的open和close方法

實現一個視窗開啟另一個視窗,五秒鐘自動關閉的功能;

源網頁為:

<html>
<head>
<script type="text/javascript">

window.open("time.html","","width=400,height=100");

</script>
</head>

<body></body>
</html>
開啟網頁為:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=gbk"/>
<title>計時方法用法</title>
<style type="text/css">
#time{width:180px;height:40px;background:#fac;margin:0 auto;font-size:11pt;padding-left:5px;padding-top:10px;color:gray;line-height:20px}
</style>
<script type="text/javascript">
	//setTimeout(update_time,1000);
	//setInterval(update_time,1000);
	var id ;
	function init(){
		id = setInterval(update_time,1000);
		<span style="color:#ff0000;">setTimeout("self.close()",5000);//self.colse()方法</span>
	}
	
	function update_time(){
		var date = new Date();
		var time = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
		document.getElementById('time').innerText = time;
	}
	
	function stop(){
		clearInterval(id);
	}
</script>
</head>
<body onload="init()">
	<div id='time'>
	</div>
	<input type="button" value="stop" onclick="stop()"/>
</body>

</html>

此頁面五秒後會自動關閉

怎麼實現向開啟的頁面中輸入內容?

<html>
<head>
<script type="text/javascript">
var win=window.open("time.html","","width=400,height=100");
win.document.write("您好!<span style="font-family: Arial, Helvetica, sans-serif;">"/></span>
<span style="font-family: Arial, Helvetica, sans-serif;">");</span>
</script>
</head>

<body></body>
</html>