2013-10-18 20 views
1

我想用fanstatic加载外部js文件。这是我如何打电话要加载的文件:如何在IE检查块中加载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文件?

回答

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)