简体   繁体   English

.php和.html。 IE为什么渲染它们不同?

[英].php vs .html . Why is IE rendering them differently?

I copied one of the html pages in a project and just changed the extension from html to php. 我在项目中复制了一个html页面,只是将扩展名从html更改为php。 The rendering is identical in all browsers but IE. 除了IE以外,所有浏览器的渲染都相同。 It seems that IE treats the pages differently based on the extension. IE似乎根据扩展名对页面进行了不同的处理。

I checked the HTTP headers and they are the same for both pages. 我检查了HTTP标头,两个页面的标头都相同。 Did anyone have the same problem? 有人遇到过同样的问题吗?

Make sure you aren't in Quirks mode . 确保您不在怪癖模式下 Most often this has been caused for my by having text before the <doctype> . 通常,这是由<doctype>之前的文本引起的。

PHP isn't configured to auto append or prepend anything to your file, is it? 没有将PHP配置为自动向文件添加或添加任何内容,是吗? Long shot, but worth checking... 远射,但值得检查...

(see the Data Handling section of this page ) (请参阅本页的“数据处理”部分)

I would start by verifying the responses are the same. 我将从验证响应是否相同开始。 Try the following, in order: 按顺序尝试以下操作:

  1. Keep the extension (.php) and configure your web server to serve it just like any html page. 保留扩展名(.php)并配置您的Web服务器以使其像任何html页面一样提供服务。 Check if the page renders differently. 检查页面的呈现方式是否不同。 If it does, it's not the extension. 如果是这样,则不是扩展名。
  2. Get the raw response (using wget -S , for example) and compare it to the response of the html page. 获取原始响应(例如,使用wget -S ),并将其与html页面的响应进行比较。
  3. Override the headers with php (using header() ) until you find the one that is responsible for the change. 用php覆盖标头(使用header() ),直到找到负责更改的header()为止。

I really doubt it's the extension, it must be something in the headers. 我真的怀疑这是扩展名,一定是标题中的内容。

Just add: 只需添加:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

at the top of your source file 在源文件的顶部

What versions of the browsers are you using? 您正在使用什么版本的浏览器? Older versions of IE produced some non-conforming output, especially connected to CSS. 较旧版本的IE产生了一些不一致的输出,尤其是与CSS连接时。 (are you using CSS?) (您使用CSS吗?)

It is quite common for some elements to be a little different in different browsers. 在不同的浏览器中某些元素有些不同是很常见的。 It is what makes web coding fun (?!) and a challenge. 这就是使Web编码有趣(?!)和挑战的原因。

And, as Darryl asked, what exactly is different? 而且,正如Darryl所问的,究竟有什么不同?

Rather than browsing the pages via HTTP to a web server, try File->Open. 与其通过HTTP浏览网页到Web服务器,不如尝试File-> Open。 That will at least eliminate or incriminate the web server. 这至少将消除或使Web服务器成为犯罪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM