HTML 打开输入流

3 篇文章 0 订阅


document = document . open( [ type [, replace ] ] )

Causes the Document to be replaced in-place, as if it was a new Document object, but reusing the previous object, which is then returned.

If the type argument is omitted or has the value "text/html", then the resulting Document has an HTML parser associated with it, which can be given data to parse using document.write(). Otherwise, all content passed to document.write() will be parsed as plain text.

If the replace argument is present and has the value "replace", the existing entries in the session history for the Document object are removed.

The method has no effect if the Document is still being parsed.

Throws an InvalidStateError exception if the Document is an XML document.


以上是html5手册中的解释。

当type省略或是“text/html",该语句就会返回一个带有html解析的文档对象,使用document.write()方法将要被解析的html内容写入到当前文档中进行解析。

如果replace 参数使用了"replace" ,就会将原来的文档移除。

当文档正在被解析的时候,这个方法不会起作用。也就是说,下面的代码是不会产生本该有的输出

<!DOCTYPE html>

<html lang="en">

<head>

  <title>test<title>

</head>

<body>

  <p>beginer</p>

  <script>

var new=document.open("text/html");

new.write("<p> this is new content</p>");

  new.close();

  </script>

</body>

</html>

即输出的内容是:

beginer

this is new content

而不是想象中的:

this is new content


该方法的另外一个作用是打开文档:

window =  document .  openurlnamefeatures [,  replace ] )   Works like the  window.open() method.

eg. <script>

document.open("http://www.baidu.com","","_self");

window.open("http://www.baidu.com","","_self");

     </script>

的作用是打开百度页面;

与window.open("http://www.baidu.com","","_self");

的作用相同.


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值