document.open(“text/plain”) formatting ignored in webkit (safari, chrome)

后端 未结 2 411
别跟我提以往
别跟我提以往 2021-01-23 03:01

I am creating a page from JavaScript using document.open(\"text/plain\") and document.write(). The text to be rendered is multiple lines of tab separated text. In Chrome 13.0.7

相关标签:
2条回答
  • 2021-01-23 03:19

    You need to use the <pre> tag around your content in order to get it to render the way you want it to. The browser is still going to treat the document you're writing the code into as an HTML document. The <pre> tag will tell the browser to render the content a pre-formatted text, which will honor all line breaks and white-space characters.

    0 讨论(0)
  • 2021-01-23 03:27

    You should drop the parameter to open() since it's not supported in other browsers, and prefix your parameter to the first write() with '<PLAINTEXT>', a beyond-deprecated tag from the depths of HTML history which does exactly what you want (it has no closing tag.)

    0 讨论(0)
提交回复
热议问题