条件注释适用于除 IE 8 及更低版本之外的所有浏览器
how can i write a conditional comment for scripts that should run for all browsers except IE 8 and below?
i saw Conditional comment for 'Except IE8' ?
but how do i adapt it to include scripts files not inline scripts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该技巧解释说,对于外部脚本也同样适用 - 在条件注释的内联脚本中设置“此浏览器是旧的”标志,并让外部脚本检查该标志。
如果您打算有条件地包含整个脚本文件,那么最好的选择可能是浏览器嗅探并动态包含适当文件的脚本。否则,您可以使用下层显示的条件注释(谢谢,bobince!)。
The trick explained there would work just as well for external scripts — set a "this browser is old" flag in a conditional-commented inline script, and have your external scripts check for that flag.
If you mean to conditionally include entire script files, your best bet would probably be a script that browser-sniffs and dynamically includes the appropriate files. Otherwise, you could use downlevel-revealed conditional comments (thanks, bobince!).