Rails 3 Conditional Inclusion of Javascript Files

I am trying to find a better way to include the following in my head in rails 3:

<!--[if IE]><script language="javascript" type="text/javascript" src="/javascripts/excanvas.min.js"></script><![endif]--> 

As you can see, I just want this javascript file to be available in IE ... so maybe I shouldn't do it that way at all ... I'm open to suggestions.

I use this to specify default javascript files to include:

config.action_view.javascript_expansions [: defaults] =% w (jquery rails jquery-ui jquery.flot)

In any case, can I specify this default excanvas.js only if the user uses IE?

What is the best way to do this?

Thank!

+3
source share
1 answer

The best way is how you do it, i.e.:

<%= javascript_include_tag :defaults %>
<!--[if IE]><%= javascript_include_tag "excanvas.min" %><![endif]-->

, useragent , - CSS/JS IE/ IE. - User-agent, , IE excanvas, :defaults. , , IE , , IE.

+3

Source: https://habr.com/ru/post/1769791/


All Articles