Detailed explanation of html browser automatically adding
 tag

黄舟
Release: 2017-07-08 13:49:43
Original
3260 people have browsed it

Problem scenario:

I clicked a request on page A, opened a new page (B), and passed HttpServlet on the backend Response.getWriter().write(html) method is used to write the information into the newly opened page B; [Digression: The reason for this is to solve the problem of the newly opened page being intercepted by the browser]

But there is no problem in IE6, 7, 8, ff; but in chrome, my newly written content is actually placed in the

 tag; <p><img src="https://img.php.cn/upload/article/000/000/194/2dca1e20198ed7fa37b2e8461817f576-0.jpg" alt="Detailed explanation of html browser automatically adding <pre class="brush:php;toolbar:false"> tag"><br></p><p><strong>About html <pre class="brush:php;toolbar:false"> tag: <excerpted from: w3school></excerpted>
Copy after login

pre element can define pre-formatting ized text. Text enclosed in a pre element usually preserves whitespace and newlines. The text will also be rendered in a fixed-width font.

 A common application of tags is to represent computer source code. <p style="margin-top:12px; margin-bottom:0px; line-height:18px; font-family:Verdana,Arial,Helvetica,sans-serif"><strong> Thoughts on the problem: </strong></p><p style="margin-top:12px; margin-bottom:0px; line-height:18px; font-family:Verdana,Arial,Helvetica,sans-serif">After discovering this problem, the first thing I thought of was: This should be because different browsers process code text information differently, chrome My form is displayed on the page as text. And <span style="color:#ff0000"> is not an element in html format; so I think everything should be fine once this problem is solved. </span></p><p style="margin-top:12px; margin-bottom:0px; line-height:18px"><span style="font-family:Verdana,Arial,Helvetica,sans-serif">At this time, I thought of the setting of html</span><span style="font-family:微软雅黑,Verdana,sans-serif,宋体"><span style="font-size:14px">meta information</span></span></p><p style="margin-top:12px; margin-bottom:0px; line-height:18px; font-family:Verdana,Arial,Helvetica,sans-serif"><span style="font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="font-family:Tahoma; line-height:18px"> <meta http-equiv="<span style=" color:>Content-Type</span>" content="</span><span style="font-family:Tahoma; line-height:18px"><span style="color:#ff0000">text/html</span></span><span style="font-family:Tahoma; line-height:18px"> ;char<a href="http://www.php.cn/code/8209.html" target="_blank">set</a>=utf-8"
 /> Setting this <a href="http://www.php.cn/wiki/169.html" target="_blank">attribute</a> should solve the problem. </span><br></p><p style="margin-top:12px; margin-bottom:0px; line-height:18px; font-family:Verdana,Arial,Helvetica,sans-serif"><span style="font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="font-family:Tahoma; line-height:18px; background-color:rgb(255,255,255)">After checking the document, it suddenly became clear: </span></span></p><p style="margin-top:12px; margin-bottom:0px; line-height:18px; font-family:Verdana,Arial,Helvetica,sans-serif"><span style="font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="font-family:Tahoma; line-height:18px"></span></span></p><p style="padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:10px; font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="padding:0px; margin:0px; color:rgb(229,51,51)"><span style="padding:0px; margin:0px; color:rgb(0,0,0); background-color:rgb(255,255,255)">1. text/html is the text in html format </span></span></p><p style="padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:10px; font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="padding:0px; margin:0px; color:rgb(229,51,51)"><span style="padding:0px; margin:0px; color:rgb(0,0,0); background-color:rgb(255,255,255)">2. text/plain is unformatted Text</span></span></p><p style="padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:10px; font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px">3. text/xml ignores the encoding format specified by the xml header and defaults to us-ascii encoding</p><p style="padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:10px; font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="padding:0px; margin:0px; color:rgb(229,51,51)"><span style="padding:0px; margin:0px; color:rgb(0,0,0); background-color:rgb(255,255,255)">4. application/xml will Encode according to the encoding format specified by the xml header </span></span></p><p><strong> Solution: </strong></p><p style="margin-top:12px; margin-bottom:0px; line-height:18px; font-family:Verdana,Arial,Helvetica,sans-serif"><span style="font-family:微软雅黑,Verdana,sans-serif,宋体; font-size:14px"><span style="font-family:Tahoma; line-height:18px"></span></span></p><pre class="brush:html;toolbar:false;">response.setHeader("Content-Type", "text/html");
Copy after login

The above is the detailed content of Detailed explanation of html browser automatically adding

 tag. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template