如何在IE检查块中加载js文件

时间:2013-10-18 18:36:19

标签: javascript python pyramid fanstatic

我正在尝试使用fanstatic加载外部js文件。这就是我调用要加载的文件的方式:

<!--[if lt IE 9]>
<%
  h.html5shiv.need()
%>
<![endif]-->

问题是当我检查源文件时,js文件被添加到标记内,但是如果检查则不在IE中。

<head>
  <script type="text/javascript" src="html5shiv.js"></script>
  <!--[if lt IE 9]>

  <![endif]-->
</head>

如果检查阻止,有没有办法强制fanstatic在IE中呈现这个js文件?

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

#import simple js renderer
from fanstatic.core import render_js

#define your custom renderer
def render_conditional_comment_js(url, condition = 'lt', version = '9'):
    return '<!--[if %s IE %s]>%s<![endif]-->' % (condition, version, render_js(url))

#create a library
jquery_lib_conditional = Library('jquery_con', 'lib') 

#use your custom renderer for render a specific resource
jquery_js_conditional = Resource(jquery_lib_conditional, 'jquery-1.9.1.js', renderer = render_conditional_comment_js)