【问题标题】:different content based on browser version?基于浏览器版本的不同内容?
【发布时间】:2012-04-24 09:54:20
【问题描述】:

是否可以根据用户使用的浏览器在 CMS (DNN) 中显示不同的内容?比如IF IE 7 则显示内容1

IE7 不太喜欢图像映射,而 id 只是向用户显示我制作的流程图的静态图像。

<!--[if IE 7]>
Special instructions for IE 7 here
<![endif]-->

我想编写一些 jquery 代码来删除内容窗格中 div 类的内容(对于该页面,因此检查文件扩展名 process.aspx),然后在隐藏的 div 中启用图像。

  1. 检测哪个浏览器(如果是ie7则:
  2. 从内容窗格中删除内容(检查 process.aspx 的 url)
  3. 使用display:block启用隐藏的div)

【问题讨论】:

  • 那么,你想用JS检测用户使用的浏览器,就这样?
  • 在编辑中添加了更多信息。

标签: jquery internet-explorer content-management-system browser dotnetnuke


【解决方案1】:

你可以使用jQuery.browser方法:

if (jQuery.browser.msie && jQuery.browser.version == '7.0') {
      $('#content').show();
}

http://api.jquery.com/jQuery.browser/

【讨论】:

  • 我在使用jQuery.browser 方法时遇到了一些问题。我终于更喜欢使用基于 CSS 的浏览器检测了。
【解决方案2】:

这里是获取IE版本的JS方法(如果不是IE则返回-1):

function isUndefined(e) {
    return typeof e === "undefined";
}

function getIEVersion() {
    var style = document.body.style;
    var version = -1;
    if(!isUndefined(style.scrollbar3dLightColor)) {
        if (!isUndefined(style.opacity)) version = 9;
        else if (!isUndefined(style.msBlockProgression)) version = 8;
        else if (!isUndefined(style.msInterpolationMode)) version = 7;
        else if (!isUndefined(style.textOverflow)) version = 6;
        else version = 5;
    }
    return version;
}

然后,使用 jQuery:

$(function() {
    if(getIEVersion() == 7) {
        $('#content-pane').hide();
        $('#hidden-div').show();
    }
});

【讨论】:

    【解决方案3】:

    老实说,你可以用 CSS 做到这一点。

    你有两条内容

    <div class="ForEveryone">
    <!-- Your stuff here -->
    </div>
    
    <div class="ForIE7">
    <!-- Code for less helpful browser here -->
    </div>
    

    然后默认有css去做

    .ForIE7 { display: none; }
    

    然后使用 IE 7 特定样式表将其更改为

    .ForEveryone { display: none; }
    .ForIE7 { display: block; }
    

    无需为此使用 javascript。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-25
      • 2011-11-30
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 2017-03-20
      • 2018-06-21
      • 2013-08-10
      相关资源
      最近更新 更多