Tuesday, January 3, 2012

Chrome/Firefox/Safari Not Able to Read External Javascript/CSS

This is something a web programmer needs to take note as this could lengthen your coding time if this is not taken into account.

Chrome/Firefox/Safari is not able to read external Javascript/CSS with commands such as:

<link rel="stylesheet" type="text/css" href="testcss.php" />
<script language="JavaScript" src="testjs.php"></script>

if your broswer runs in STANDARD mode (with the declaration of DOCTYPE).











Fix:

1) Include your CSS/JAVASCRIPT in your HTML file that you are running, to prevent referring to an external CSS/JAVASCRIPT

2) Run your browser in QUIRK mode (do not declare any DOCTYPE)

3) Use PHP to spit out DOCTYPE if IE browsers are detected


I would put codes like these before the <HTML> in my whatever.php:


<?php
error_reporting(0); // This is needed if your PHP spits errors/warnings to your browser
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
echo('<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
}
?>

No comments:

Post a Comment