php 包含条件注释
我在我的网站上包含了一些 jQuery 脚本。该脚本不适用于 IE7 以下的任何版本。现在我想做以下事情:
<!--[if !(lt IE 7]>
<?php include 'script.html'; ?>
<![endif]-->
它应该只在浏览器“不低于IE7”的情况下加载脚本。 但这不起作用。
有没有办法不使用基于 PHP 的浏览器识别来解决这个问题?
I included some jQuery script on my site. The script doesn't work with anything lower than IE7. Now I want to do the following:
<!--[if !(lt IE 7]>
<?php include 'script.html'; ?>
<![endif]-->
It should only load the script if the browser is "not lower than IE7".
But it doesn't work.
Is there any way to solve this without using a PHP based browser recognition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,将浏览器识别构建到您的 jQuery/javascript 中。在 JavaScript 中,测试您需要的功能或对象,如果不存在,则使用代码来处理它。
Yes, build the browser recognition into your jQuery/javascript. In the javascript, test for capability or object you're needing, and if it's not there, then have code to deal with it.
可能是开头(没有结尾)?
could be the opening ( that doesn't have a closing ) ?
帮助第一部分:它不起作用,因为您不需要
lte
之前的(
,也不需要!
。使用进一步阅读: 微软关于 IE 条件注释的页面
Help with the first part: it doesn't work because you don't need the
(
beforelte
, nor the!
. UseFurther reading: Microsoft's page on IE conditional comments
另一种选择是使用众所周知的 ie7.js 脚本,它使旧版 IE 更加“标准”兼容,这肯定会让您的 jQuery 脚本正常工作。
您可以在此处找到它
another alternative can be to use the well known ie7.js script that makes older IE versions more "standard" compliant that would surely make your jQuery script work.
you can find it here
您不应该使用浏览器检测。相反,请使用功能检测来测试您的浏览器是否能够执行您想要的功能做。
You shouldn't be using browser detection. Instead, use Feature Detection to test if your browser is capable of something you want to do.
在 php 中,您将执行以下操作之一
或
IE 条件语句仅在页面发送到浏览器后才起作用,因此 PHP 包含文件将不起作用,要包含您将使用的 JS 脚本文件
对于 javascript 浏览器检测,您将使用:
in php you would do one of the following
OR
The IE Conditional statements only work after the page has been sent to the browser so PHP include files will not work, To include a JS script file you would use
For a javascript browser detection you would use: