window对象的open和close方法_javascript

window对象的open和close方法_javascript_02

实现一个窗口打开另一个窗口,五秒钟自动关闭的功能;

源网页为:

<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 οnlοad="init()">
<div id='time'>
</div>
<input type="button" value="stop" οnclick="stop()"/>
</body>

</html>


window对象的open和close方法_css_03

此页面五秒后会自动关闭

怎么实现向打开的页面中输入内容?

<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>


window对象的open和close方法_css_04