【问题标题】:remove all styles based on browser version根据浏览器版本删除所有样式
【发布时间】:2012-04-06 20:48:44
【问题描述】:

我想知道如何通过检查浏览器是否低于 IE8 来删除所有 css 样式。

所以如果它检测到 IE7 则删除所有样式?我想知道这是否可以通过一些 jquery 实现?

这会解决大多数 IE7 问题吗:

<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE7.js"></script>
<![endif]-->

【问题讨论】:

  • 你放在那里的内容检查IE版本是否小于 7,换句话说,IE6或更低。您的意思可能是[if lte IE 7][if lt IE 8]

标签: javascript jquery css internet-explorer-7 cross-browser


【解决方案1】:

我不知道您为什么要删除浏览器版本的所有样式。我想你在使用 IE7 时遇到了一些 CSS 问题,通常修复它的好方法是使用 ie7.js:http://code.google.com/p/ie7-js/,而不是删除所有 CSS。

这是demo 的功能。

另外,这个脚本有 IE8 和 IE9 的版本。

【讨论】:

  • 我只是将它粘贴到标题中吗?
  • ie7.js 不会像您要求的那样删除任何 CSS。它只是试图使 IE7 的行为方式与其他版本/浏览器相同...
  • jamie,IE7.js 对我的页面没有任何作用。我可以检查它的唯一方法是兼容模式。
  • @Jamie。是的,我知道。我应该很清楚,我并没有试图回答这个问题,而是提供了一种替代方法,而不是删除所有样式。
【解决方案2】:
<!--[if lt IE 8]>
    <body class='oldIE'>
<![endif]-->
<!--[if gte IE 8]>
    <body class='ok'>
<![endif]-->
<!--[if !IE]>
    <body class='ok'>
<![endif]-->

这里你需要在所有你不使用 IE7 的样式前加上 .ok

另一种方法是

<!--[if lt IE 8]>
    //include an old IE specific stylesheet or none at all
<![endif]-->
<!--[if gte IE 8]>
    //include your stylesheets
<![endif]-->
<!--[if !IE]>
    //include your stylesheets
<![endif]-->

【讨论】:

  • 我最终使用了 if lt IE8,然后设置了一些 javascript 来触发以重定向到一个启动页面,说 IE7 或
【解决方案3】:

最好的解决方案是删除特定的类名,而不是擦除元素的整个 CSS:

// Identity browser and browser version

if($.browser.msie && parseInt($.browser.version) == 7) {

   // Remove class name
   $('.class').removeClass('class');

   // Or unset each CSS selectively
   $('.class').css({
      'background-color': '',
      'font-weight': ''
   });

}

【讨论】:

  • 这是否可行,因为我在 UL.tiles 上有 5 种样式。我基本上想让页面像互联网刚开始时一样。或者只是将他们重定向到一个页面,说 IE7 糟透了。
  • 如果有样式表规则,"unsetting css" with .css(编辑内联样式)不会执行任何操作。此外,并非所有的 CSS 规则都是基于类的。
猜你喜欢
  • 2012-07-28
  • 1970-01-01
  • 1970-01-01
  • 2020-06-27
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多