简体   繁体   English

如果IE document.mode <8,则插入JavaScript文件

[英]Insert JavaScript file if the IE document.mode < 8

I have the following script within the head of my ASP.Net page. 我在ASP.Net页面的头部有以下脚本。 This will only include script file if the IE version is less than 8, but if the IE version is 10 and document mode is 7 then this script will not get included. 如果IE版本小于8,则仅包括脚本文件,但如果IE版本为10且文档模式为7,则不会包含此脚本。

Is there a way to include dynamically javascript file based on document.mode value using similar notation? 有没有办法使用类似的表示法基于document.mode值包含动态javascript文件?

<!--[if lt IE 8]>
  <script src="xyz.js">
<![endif]-->

EDIT 1: the following gave unterminated string error in IE 10. 编辑1:以下在IE 10中给出了未终止的字符串错误。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title></title>
  <script>/*<![CDATA[*/if(document.documentMode==7)document.write("<script src=\"xyz.js">
    </script>");/*]]>*/</script>
 </head>

Dynamically Include a javascript file 动态包含javascript文件

It's not an IE conditional comment, but it will dynamically include a JavaScript file based on the documentMode and will not affect other browsers. 它不是IE条件注释,但它会动态地包含基于documentMode的JavaScript文件,不会影响其他浏览器。 Choose which one you like best: 选择你最喜欢的一个:

<script>/*<!--*/if(document.documentMode==7)document.write('<script src="xyz.js"><\/script>');/*-->*/</script>

<script>/*<![CDATA[*/if(document.documentMode==7)document.write('<script src="xyz.js"><\/script>');/*]]>*/</script>

<script>if(document.documentMode==7)document.write('<script src="xyz.js"><\/script>');</script>

Thanks @Jonathan Lonowski for the last option! 感谢@Jonathan Lonowski的最后一个选择!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM