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

javascript - jQuery - IE ONLY css - Stack Overflow

programmeradmin3浏览0评论

Is it possible to use

var script = document.createElement('link');
script.href = 'theme/style/ie/manageleads.css';
script.rel  = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);

and for it to only be active if the browser is IE8?

Is it possible to use

var script = document.createElement('link');
script.href = 'theme/style/ie/manageleads.css';
script.rel  = 'stylesheet';
script.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(script);

and for it to only be active if the browser is IE8?

Share Improve this question edited Nov 5, 2014 at 11:22 Joe 15.8k4 gold badges50 silver badges83 bronze badges asked Sep 12, 2011 at 2:37 RussellHarrowerRussellHarrower 6,85025 gold badges113 silver badges225 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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

Note that IE8 claims to be 7 in Compatibility View.

if ($.browser == 'msie' && (parseInt($.browser.version) == 8 || parseInt($.browser.version) == 7))
{
    // Do something IE8-only in here
}

The best way would be conditional CSS, but since you asked for jQuery, here ya go.

if ($.browser.msie && parseInt($.browser.version) == 8) {
  $('<link />', {
    href: 'theme/style/ie/manageleads.css',
    rel: 'stylesheet',
    type: 'text/css'
  }).appendTo('head');
}

If that doesn't work, let me know. You might need to use 'document.createStylesheet' instead.

发布评论

评论列表(0)

  1. 暂无评论