简体   繁体   English

有没有办法把PHP放在IE条件评论中

[英]Is there a way to put php inside of a IE conditional comments

I have a php section that loads jquery through wordpress from google's api. 我有一个php部分,通过google的api中的wordpress加载jquery。 I dont want to load jquery on IE browsers. 我不想在IE浏览器上加载jquery。 Long story short, it doesn't work for whatever reason (you can read through my other posted questions). 长话短说,它无论出于何种原因都不起作用(你可以阅读我发布的其他问题)。

Or if this is not possible is there another way to NOT use this code when its an IE browser, maybe a php solution. 或者,如果这是不可能的,还有另一种方法,当它的IE浏览器,可能是一个PHP解决方案时不使用此代码。

<?php 
    if( !is_admin()){
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2', true);
        wp_enqueue_script('jquery');
    }

?>

Targets everything except IE (what i was trying to use, but it didnt work): 目标除了IE之外的一切(我试图使用的,但它没有用):

<!--[if !IE]><!-->
<!--<![endif]-->

你在Wordpress中拥有全局$ is_IE。

No. You'd probably want to detect the browser in a PHP block as an alternative solution. 不。您可能希望在PHP块中检测浏览器作为替代解决方案。 Something like: 就像是:

$browser = get_browser();
if ($browser->browser == 'MSIE') {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2', true);
        wp_enqueue_script('jquery');
    }
}

Or using the $is_IE global variable as in Nikolay Yordanov's answer: 或者使用$is_IE全局变量,如Nikolay Yordanov的回答:

if ($is_IE) {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2', true);
        wp_enqueue_script('jquery');
    }
}

Short answer: no. 简答:不。

Long answer: IE conditional comments are client side, while PHP is server side, so it won't work. 答案很长:IE条件注释是客户端,而PHP是服务器端,所以它不起作用。

Possible solution: http://php.net/manual/en/function.get-browser.php (or according to one of the answers already posted, wordpress provides a $is_IE global) 可能的解决方案: http//php.net/manual/en/function.get-browser.php (或根据已发布的答案之一,wordpress提供$ is_IE全局)

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

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