我已经创建了一个写出来的JS这样的代码PHP文件:创建一个PHP文件,JavaScript代码 - Safari /铬不起作用
<?
//my_js.php
// javascript header
header('Content-type: text/javascript');
// Date in the past
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// always modified
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// HTTP/1.1
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
?>
//
// js code here
//
然后我包括上面我的索引脚本PHP文件是这样的:
<script type="text/javascript" src="my_js.php?id=<? echo $id ?>">
</script>
这在Firefox完美,但Safari和Chrome不包括my_js.php文件在所有!
我做错了什么?
**编辑:
这是在index.php文件呈现的HTML:
<script type="text/javascript" src="my_js.php?id=new"></script>
,这是my_js.php代码: (这是一个非常大的文件,所以我只写了前几行)
var g = { sitepath: "myNullUrl" }
function getBrowserWidth(){
if (window.innerWidth){
return window.innerWidth;}
else if (document.documentElement && document.documentElement.clientWidth != 0){
return document.documentElement.clientWidth; }
else if (document.body){return document.body.clientWidth;}
return 0;
}
这是一个奇怪的问题,“而我从克罗姆/ Safari浏览器查看源代码,我可以访问js文件COS和它似乎没有错误!
我使用的是Chrome 6.04和Safari 5,均适用于Mac。
请出示成品,呈现HTML。在这种情况下,PHP代码没有意义。 – 2010-09-06 19:24:29
请不要使用短打开的标签('<?'和'<?='而不是'<?php'和'<?php echo')它不仅符合标准,而且还引入了可移植性问题。 – NullUserException 2010-09-06 19:25:57
不应该''? >'结束标记创建一个解析错误? – 2010-09-06 19:27:14