最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer - IE 7 condition with javascript - Stack Overflow

programmeradmin1浏览0评论

how can I get the name of the browser ( I'm interested in getting IE7 because it creates problems for me) by using javascript?

Reason why I want a browser name so I can assign class to one of my footer elements which doesn't look good in IE7.

I want to do this on page load, #1 check browser name , 2# if IE 7 assign class to element else do nothing. Is this the right approach by the way ? thank you

UPDATE

I have HTML something like this

<div id="some_div">
 some content
</div>

Can I use IE conditional ments and how? obviously if I put another div in front or below this div which appears only in IE both divs will appear in IE7 then.

how can I get the name of the browser ( I'm interested in getting IE7 because it creates problems for me) by using javascript?

Reason why I want a browser name so I can assign class to one of my footer elements which doesn't look good in IE7.

I want to do this on page load, #1 check browser name , 2# if IE 7 assign class to element else do nothing. Is this the right approach by the way ? thank you

UPDATE

I have HTML something like this

<div id="some_div">
 some content
</div>

Can I use IE conditional ments and how? obviously if I put another div in front or below this div which appears only in IE both divs will appear in IE7 then.

Share Improve this question edited Dec 9, 2009 at 14:03 Gandalf StormCrow asked Dec 9, 2009 at 13:58 Gandalf StormCrowGandalf StormCrow 26.2k71 gold badges179 silver badges268 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Don't do this with JavaScript, do it with a conditional ment:

<!--[if IE 7]>
 ... some code only for IE 7
<![endif]-->

While you can't really alter your page structure in such conditional ments the canonical way to use them is simply to include an additional stylesheet with fixes in your <head>:

#footer {
   /* fixes here */
}
<!--[if IE 7]>
<script type="text/javascript">IE7=true;</script>
<![endif]-->
<script type="text/javascript">
if (IE7) {
  /* do fancy error correction here... */
}
</script>

Another link about conditional ments.

Html markup

<!--[if IE 7]><html class="ie7"><![endif]-->
<!--[if IE 8]><html class="ie8"><![endif]-->
<!--[if gt IE 8]><!--><html class=""><!--<![endif]-->

CSS

#some_div {
    /* normal css */
}

/*below css will be applied only for IE7*/

.ie7 #some_div {
    /* your css for IE7 goes here */
}

you may find more useful info http://www.paulirish./2008/conditional-stylesheets-vs-css-hacks-answer-neither/ here

Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论