📄 498.html
字号:
<STYLE type=text/css>
<!--
body,td { font-size:9pt;}
hr { color: #000000; height: 1px}
-->
</STYLE>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>论坛精华 >> javascript小栈 >> JavaScript窗口功能指南之在窗口中书写内容</title>
</head>
<body >
<p><IMG SRC="../image/jsp001_middle_logo.gif" WIDTH="180" HEIGHT="60" BORDER=0 ALT=""></p>
<table width=100% bgcolor="#cccccc" align=center cellpadding="2" cellspacing="0" border=1 bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr bgcolor="#EFF8FF"><td>
<a href=http://www.jsp001.com/list_thread.php?int_attribute=4>论坛精华</a>
>> <a href=http://www.jsp001.com/list_thread.php?forumid=46&int_attribute=4>javascript小栈</a>
>> JavaScript窗口功能指南之在窗口中书写内容 [<a href=http://www.jsp001.com/forum/showthread.php?goto=newpost&threadid=498>查看别人的评论</a>]<br>
<hr><p>由 amtd 发布于: 2001-02-20 09:22</p><p><img src="images/icons/icon1.gif" alt="Post" border=0> </p><p>JavaScript窗口功能指南之在窗口中书写内容<br>(作者:听风编译 2001年01月19日 11:35)<br><br> window.open()方法打开一个新窗口,document.open()方法打开一个新文档,在其中可以使用write()或者writeln()方法书写内容,它的语法是: <br><br> oNewDoc = document.open(sMimeType[, sReplace]); <br><br> sMineType是一个字符串,它定义了MIME类型。Navigator支持几种不同的MIME类型,但是Internet Explorer当前仅仅支持“text/html”。sMineType参数是可选的。第2个参数也是一个字符串,它定义了被书写的新文档是否要替换当前文档在历史记录中的位置。如果想达到替换目的,就使用字符串“replace”。 <br><br> “replace”基本上使用于拥有空文档或者“about:blank”URL的窗口。定义了“replace”后,write()方法就可以在这个窗口中创建HTML内容,并且替换当前URL在历史记录中的位置。如果没有定义“replace”,建立的HTML就有它自己的历史位置,用户可以点击后退按钮向前直到空为止。 <br><br> 看看下面的脚本程序段: <br><br> var oNewDoc = document.open("text/html", "replace"); <br><br> var sMarkup = "<HTML><HEAD><TITLE>New Document</TITLE></HEAD>"; <br><br> sMarkup += "<BODY>Hello, world!<BR><A HREF='write.html'>Return</A></BODY></HTML>"; <br><br> oNewDoc.write(sMarkup); <br><br> oNewDoc.close(); <br><br> 如你所见,我们在新文档中包含了一个链接,所以你就可以返回这个页面。如果你点击了浏览器的后退按钮,浏览器就返回到这个页面之前的页面。因为我们使用了“replace”参数,新文档(被书写的文档)替换了当前文档在历史记录中的位置,所以点击后退按钮不会返回到当前页面(包含脚本程序的页面)。下面的按钮执行同样的脚本程序,但是没有“replace”参数,所以,你可以通过点击浏览器的后退按钮返回到这个页面。 <br><br> 以下是这个按钮的源代码: <br><br> <script language=JavaScript> <br><br> <!-- <br><br> function writeDocBack() { <br><br> var oNewDoc = document.open("text/html"); <br><br> var sMarkup = "<HTML><HEAD><TITLE>New Document</TITLE></HEAD>"; <br><br> sMarkup += "<BODY>Hello, world!</BODY></HTML>"; <br><br> oNewDoc.write(sMarkup); <br><br> oNewDoc.close(); <br><br> } <br><br> // --> <br><br> </script> <br><br> <form><input onClick=writeDocBack() type=button value="Write Document" name="button2"></form> <br><br> 正如你在上面2个例子中看到的,最后一个语句关闭了输出流: <br><br> oNewDoc.close(); <br><br> 通常,document.close()方法关闭输出流,并且强迫发送的数据显示出去。 <br><br>在新窗口中书写内容 <br> 看看下面的脚本程序: <br><br> var win = window.open("", "win", "width=300,height=200"); // a window object <br><br> win.document.open("text/html", "replace"); <br><br> win.document.write("<HTML><HEAD><TITLE>New Document</TITLE></HEAD> <br><br> <BODY>Hello, world!</BODY></HTML>"); <br><br> win.document.close(); <br><br> 第1个语句打开一个新窗口,它使用了一个空文档参数(“”),返回值分配给变量win。然后,我们使用新窗口的文档对象win.document,在其中书写一些HTML。定义“replace”是非常必要的,因为我们不想让一个空白页面在历史记录中占有一项。 <br><br> 因为我们处理同样的document对象,也许也要分配给它另外一个变量: <br><br> var win = window.open("", "win", "width=300,height=200"); // a window object <br><br> var doc = win.document; <br><br> doc.open("text/html", "replace"); <br><br> doc.write("<HTML><HEAD><TITLE>New Document</TITLE></HEAD><BODY>Hello, <br><br> world!</BODY></HTML>"); <br><br> doc.close(); <br><br> 我们也可以使用with语句: <br><br> var win = window.open("", "win", "width=300,height=200"); // a window object <br><br> with (win.document) { <br><br> open("text/html", "replace"); <br><br> write("<HTML><HEAD><TITLE>New Document</TITLE></HEAD><BODY>Hello, <br><br> world!</BODY></HTML>"); <br><br> close(); <br><br> }<br>__________________<br><font color=red>真实源于生活! </font><br>请访问我们的网站: <br>(VB爱好者乐园) <br><a href="http://www.vbgood.com" target=_blank>http://www.vbgood.com</a><br><a href="http://www.d1vb.com" target=_blank>http://www.d1vb.com</a><br><a href="http://61.128.97.225/vbgood/index.asp" target=_blank>http://61.128.97.225/vbgood/index.asp</a><br>拥有1800多个资料! </p></td>
</tr>
</table>
<p>
<CENTER><a href="http://www.jsp001.com/forum/newreply.php?action=newreply&threadid=498">点这里对该文章发表评论</a></CENTER>
<p>该文章总得分是 <font color=red>0</font> 分,你认为它对你有帮助吗?
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=498&intVote=4","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>非常多</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=498&intVote=2","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>有一些</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=498&intVote=1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>无帮助</a>](<font color=red>0</font>)
[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=498&intVote=-1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>是灌水</a>](<font color=red>0</font>) </p>
<script language="javascript" src="http://www.jsp001.com/include/read_thread_script.php?threadid=498"></script>
<p><CENTER>
Copyright © 2001 - 2009 JSP001.com . All Rights Reserved <P>
<IMG SRC="../image/jsp001_small_logo.gif" WIDTH="85" HEIGHT="30" BORDER=0 ALT="">
</CENTER></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -