WordPress - 仅在LT IE 9时排队脚本 [英] WordPress - Enqueue scripts for only if LT IE 9

查看:127
本文介绍了WordPress - 仅在LT IE 9时排队脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WordPress主题中,您如何有条件地包含ie8及以下的脚本?这主要是为各种html5 / css3功能应用polyfill。我看到wp有$ is_IE变量,它可以用作条件只包含IE的脚本。有没有办法只为某些版本的IE添加脚本而不是全部?这对于一些HTML即条件注释很简单,但是我想将这些脚本全部包含在我的函数文件中的相同位置。

In a WordPress theme, how do you conditionally include scripts for ie8 and below? This is primarily to apply polyfills for various html5/css3 features. I see that wp has the $is_IE variable which can be used as a conditional to only include scripts for IE. Is there a way to add the script for only certain versions of IE though rather than all of them? This is simple with some HTML ie conditional comments, but I'd like to include the scripts all in the same place in my functions file.

HTML中特定版本的条件:

Conditional for specific versions in HTML:

<! - [if lt IE 9]> < script src =iepolyfill.min.js>< / script> <![endif] - >

WP中所有IE的条件:

Conditional for all IE in WP:

    global $is_IE;

    if ( $is_IE ) {
        wp_enqueue_script( 'iepolyfill', bloginfo('stylesheet_directory').'/js/iepolyfill.min.js' );
    }

我环顾四周,主要查找有关wp后端条件脚本的详细信息。

I've looked around and mainly find details about conditional scripts for wp backend only.

有什么建议吗?

推荐答案

因为wordpress是一个PHP脚本,它可以通过$ _SERVER访问服务器变量

As wordpress is a PHP script, it can access server variable via $_SERVER

然后你可以用PHP搜索检测浏览器, PHP:如果是Internet Explorer 6,7,8或9

Then you can search for detect browser with PHP, PHP: If internet explorer 6, 7, 8 , or 9

这篇关于WordPress - 仅在LT IE 9时排队脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆