Hiding some HTML from IE6?

2020-02-10 06:18发布

I've tried:

<!--[if lt IE 6.0]>
HTML TO HIDE FROM IE6
<![endif]-->        

but unfortunately the stuff gets hidden from firefox too. Anyone have methods that work? I want the stuff to be hidden from only IE6

Thanks

6条回答
乱世女痞
2楼-- · 2020-02-10 06:42

Little confused with your question but Here is the javascript code to detect the version of Internet Explorer. Taken from Detecting Internet Explorer More Effectively. Add the HTML contents which are to be hidden from IE6 in a div and hide it using the function below.

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver == 6.0 ) 

            **Hide the DIV here**

  }
  alert( msg );
}
查看更多
混吃等死
3楼-- · 2020-02-10 06:45

Try

<!--[if lte IE 6.0]>

in your CSS, using lte (less-than or equal) rather than lt (less-than).

查看更多
聊天终结者
4楼-- · 2020-02-10 06:46

Natalie Downe's answer is good enough, but there's a shorter and clearer version to hide content from IE6 (or whatever version below 10):

<!--[if !IE 6]><!-->IE6 can't see me<!--<![endif]-->

To target IE6 and below, you can use

<!--[if gt IE 6]><!-->IE6 and lower can't see me<!--<![endif]-->

And if you want to support IE10+ only, you can use

<!--[if !IE]><!-->IE9 and lower can't see me<!--<![endif]-->

In fact, IE10+ doesn't support conditional comments. Inspired by Browserhacks.

Every other browser can see the content, of course, since it's all valid HTML.

查看更多
迷人小祖宗
5楼-- · 2020-02-10 06:49

Edit

After reading Natalie Downe's answer, I'd do it like this:

<!--[if true]><![if !IE]><![endif]-->
<h1>You're not using IE. Well done!</h1>
<!--[if true]><![endif]><![endif]-->

You can use negated conditional comments to hide things from IE but not from other browsers.

<!DOCTYPE html>

<html>
<head>
<title></title>
<style type="text/css"></style>
<script type="text/javascript"></script>
</head>
<body>

<![if !IE]>
<h1>You're not using IE. Well done!</h1>
<![endif]>

</body>
</html>

It renders some invalid markup, but it works.

Reference: http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

查看更多
Lonely孤独者°
6楼-- · 2020-02-10 07:00

You can actually use conditional comments to hide things from Internet Explorer contrary to the answer from deceze. These types of conditional comments are called 'Downlevel Reveal Conditional Comments'. (These are different from comments used to show things to internet explorer which are more common, those are known as 'Downlevel hidden conditional comments')


<!--[if lte IE 6]><![if gte IE 7]><![endif]-->
<!-- This is a bit mad, but code inside here is served to everything 
    except browsers less than IE7, so all browsers will see this -->
<!--[if lte IE 6]><![endif]><![endif]-->

However if you already using a downlevel hidden conditional comment to show a IE6 stylesheet just to IE6 then you might be best off just hiding it with CSS.

I hope this helps.

查看更多
地球回转人心会变
7楼-- · 2020-02-10 07:05

Conditional comments shouldn't affect Firefox at all as they are commented out and the browser should ignore it. I would check that your Firefox stylesheet is correct and embeded correctly something like this:

<link href="/css/main.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 7]>
<link href="/css/ie6.css" rel="stylesheet" type="text/css" media="screen"/>
<![endif]-->
查看更多
登录 后发表回答