HTML渲染问题-适用于Mozilla Firefox,但不适用于Google Chrome


HTML render issue - works in Mozilla Firefox, but not on Google Chrome

下面的Php文件在Mozilla Firefox中表现得非常好。然而,当在谷歌Chrome上运行相同的程序时;结果-它显示整个HTML代码,而不是呈现它。基本上表明谷歌Chrome浏览器无法理解和显示HTML代码。

abc.php文件

  <?php  
session_start();//session is a way to store information (in variables) to be used across multiple pages.  
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.3.js"></script>        
.... //some lines of code
</html>

问题是

而Firefox浏览器解析并呈现HTML代码。Google Chrome无法理解php文件本身就是一个HTML代码。

解决方案

将DOCTYPE行放置为文件的第一行

因此,改变在于DOCTYPE行的位置,该DOCTYPE行指示要在浏览器上显示的文档的类型。

abc.php文件

<!DOCTYPE html>
<?php  
session_start();//session is a way to store information (in variables) to be used across multiple pages.  
?>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.3.js"></script>        
.... //some lines of code
</html>
相关文章: