打开新窗口并输出内容

来源:互联网 发布:sql 取前三大的值 编辑:程序博客网 时间:2024/06/18 17:40
一 介绍
打开新窗口并输出内容可以使用open()方法和close()方法来实现。
open()方法
该方法用来打开文档输出流,并接收write()方法或writeln()方法的输出,此方法可以不指定参数。
语法:
[obj=]document.open([url][,name])
obj:用来存储open()方法返回的值,obj是可选项。
url:用来指定打开文档或窗口的URL。
name:用来指定是否用新的URL代替历史记录旧的URL,当指定为replace表示代替,不指定则不代替。
close()方法
该方法用来关闭文档的输出流。
语法:
document.close()
 
二 应用
打开新窗口并输出内容
本示例通过单击按钮后将打开一个新窗口,并在窗口中输出新的内容。
 
三 代码
<html ><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>打开新窗口并输出内容</title><script language="javascript"> <!-- function oc() { var dw; dw=window.open(); dw.document.open(); dw.document.write("<html><head><title>一个新的窗口</title>"); dw.document.write("<body>"); dw.document.write("<img name='i1' src='Temp.jpg'> <br>") dw.document.write("这里是写入的新内容<br>");  dw.document.write("</body></html>"); dw.document.close(); } --></script></head><body><input type="button" value="打开一个新文档" onclick="oc();"/></body></html>
 
 
四 运行结果