查克诺里斯推特小部件正在失去IE的风格

gin*_*ime 6 javascript css jquery asynchronous

在IE上异步加载twitter小部件时遇到一个奇怪的问题.它加载得很好,但由于某种原因不适用于IE(7,8,9)上的任何样式(颜色,背景为空白/默认).

以标准方式加载脚本也适用于IE.

代码看起来像这样,适用于所有浏览器(包括IE,但没有样式)

<div id="twitter_div"></div>
<script>
    jQuery(window).load(function () {
        jQuery('<link rel="stylesheet" type="text/css" href="http://widgets.twimg.com/j/2/widget.css" >').appendTo("head");
        jQuery.getScript('http://widgets.twimg.com/j/2/widget.js', function () {
            var twitter = new TWTR.Widget({
              id: 'twitter_div',
              version: 2,
              type: 'profile',
              rpp: 4,
              interval: 6000,
              width: 'auto',
              height: 300,
              theme: {
                shell: {
                  background: '#add459',
                  color: '#382638'
                },  
                tweets: {
                  background: '#ffffff',
                  color: '#141114',
                  links: '#4aed05'
                }   
              },  
              features: {
                scrollbar: false,
                loop: false,
                live: false,
                hashtags: true,
                timestamp: true,
                avatars: false,
                behavior: 'all'
              }   
            }).render().setUser('chucknorris').start();
        })
    })
</script>
Run Code Online (Sandbox Code Playgroud)

你可以在这个链接上看到这个.

即使设置为chucknorris,它也会失去IE上的风格.

Azd*_*325 1

你认为将CSS放在你自己的CSS中以避免出现问题

<style type="text/css">
#twitter_div .twtr-doc, #twitter_div .twtr-hd a, #twitter_div h3, #twitter_div h4 {
background-color: #ADD459 !important;
color: #382638 !important;
}
#twitter_div .twtr-bd, #twitter_div .twtr-timeline i a, #twitter_div .twtr-bd p {
color: #141114 !important;
}
#twitter_div .twtr-avatar {
display: none;
}
#twitter_div .twtr-new-results, #twitter_div .twtr-results-inner, #twitter_div .twtr-timeline {
background: white !important;
}
#twitter_div .twtr-tweet a {
color: #4AED05 !important;
}
</style>
Run Code Online (Sandbox Code Playgroud)

如果将其放入 main.css 文件中,可以获得更好的静态内容缓存体验,并且全部集中在一个位置,这也是件好事

<script>
    jQuery(window).load(function () {
        $("head").append("<link rel='stylesheet' type='text/css' href='http://widgets.twimg.com/j/2/widget.css' />");
        jQuery.getScript('http://widgets.twimg.com/j/2/widget.js', function () {
            var twitter = new TWTR.Widget({
              id: 'twitter_div',
              version: 2,
              type: 'profile',
              rpp: 4,
              interval: 6000,
              width: 'auto',
              height: 300,
              theme: {
                shell: {
                  background: '#add459',
                  color: '#382638'
                },  
                tweets: {
                  background: '#ffffff',
                  color: '#141114',
                  links: '#4aed05'
                }   
              },  
              features: {
                scrollbar: false,
                loop: false,
                live: false,
                hashtags: true,
                timestamp: true,
                avatars: false,
                behavior: 'all'
              }   
            }).render().setUser('chucknorris').start();
        })
    })
</script>
Run Code Online (Sandbox Code Playgroud)