Javascript 需要twitter小部件的帮助吗
我创建了一个jquery插件,它在左侧为社交媒体内容放置了一个侧栏。我有下面的变量,这就是内容的来源。我正试图使用这个小部件获取twitter提要,但我一直收到错误“TWTR未定义”。有没有办法解决这个问题 此页面正在调用我创建的插件Javascript 需要twitter小部件的帮助吗,javascript,jquery,html,css,twitter,Javascript,Jquery,Html,Css,Twitter,我创建了一个jquery插件,它在左侧为社交媒体内容放置了一个侧栏。我有下面的变量,这就是内容的来源。我正试图使用这个小部件获取twitter提要,但我一直收到错误“TWTR未定义”。有没有办法解决这个问题 此页面正在调用我创建的插件 var内容=( “FB内容区”+ '新TWTR.Widget({version:2,type:\'profile\',rpp:4,间隔:6000,宽度:250,高度:280,主题:{shell:{background:\'333333\',color:\'ffff
var内容=(
“FB内容区”+
'新TWTR.Widget({version:2,type:\'profile\',rpp:4,间隔:6000,宽度:250,高度:280,主题:{shell:{background:\'333333\',color:\'ffffffff\',tweets:{background:'ffffffff\',color:'444444\',链接:\''e02046\},特性:{滚动条:false,循环:false,live:false,hash:false,时间标签:true,行为:}.render().setUser(\'CSuitesIndepend\').start();'+
“Youtube视频”+
“Yelp评论”+
“旅行顾问建议”+
“链接页面”
);
另外-如果我从插件中删除这一行
,并将其放在我的网页头部,我所看到的就是twitter提要
编辑:好的,现在我在想,为什么我不能添加twitter小部件代码-
新TWTR.Widget({
版本:2,
键入:“配置文件”,
rpp:4,
间隔时间:6000,
宽度:250,
身高:280,
主题:{
外壳:{
背景:"333333",,
颜色:“#ffffff”
},
推特:{
背景:“#ffffff”,
颜色:“#4444”,
链接:“#e02046”
}
},
特点:{
滚动条:false,
循环:false,
生活:假,
hashtags:true,
时间戳:对,
阿凡达:错,
行为:“全部”
}
}).render().setUser('CSuitesIndepend').start();
-通过插件动态插入的元素
当我尝试此代码时,它不会在#tweetFeed-
$(document).ready(function() {
// add the sidebar plugin
$('html').social(function() {
//console.log('#tweetFeed = '+ $('#tweetFeed').parent().html());
$('#tweetFeed').insertAfter("<p>TEST</p>");
});
//console.log('#tweetFeed = '+ $('#tweetFeed').parent().html());
$('#tweetFeed').insertAfter("<p>TEST</p>");
});
$(文档).ready(函数(){
//添加边栏插件
$('html').social(函数(){
//log('#tweetFeed='+$('#tweetFeed').parent().html());
$(“#tweetFeed”)。在(“测试””)之后插入;
});
//log('#tweetFeed='+$('#tweetFeed').parent().html());
$(“#tweetFeed”)。在(“测试””)之后插入;
});
在添加的标记中放置对twitter js文件的引用,同时在该脚本中放置对对象的引用。下载twitterjs文件需要一秒钟左右的时间,但浏览器仍会继续解析您的内联脚本
因此,要做的第一件事是从标记变量中删除对twitter脚本的引用,使用$.getScript()获取它,并使用$getScript的回调添加标记,以便它仅在twitter中的js到达浏览器后运行内联。差不多吧
var content = (
'<div class="contentArea visible" id="fb">FB Content Area</div>'+
'<div class="contentArea" id="twit"><script>new TWTR.Widget({version: 2,type: \'profile\',rpp: 4,interval: 6000,width: 250,height: 280,theme: {shell: {background: \'#333333\',color: \'#ffffff\'},tweets: {background: \'#ffffff\',color: \'#444444\',links: \'#e02046\'}},features: {scrollbar: false,loop: false,live: false,hashtags: true,timestamp: true,avatars: false,behavior: \'all\'}}).render().setUser(\'CSuitesIndepend\').start();</script></div>'+
'<div class="contentArea" id="youtube">Youtube Video</div>'+
'<div class="contentArea" id="yelp">Yelp reviews</div>'+
'<div class="contentArea" id="ta">Trip Advisor Advice</div>'+
'<div class="contentArea" id="li">The Linked In Page</div>'
);
$.getScript("http://widgets.twimg.com/j/2/widget.js",function(){
// dynamically add the get social sidebar
$('body').prepend('<div id="social"><div id="outer"><span><img src="getSocial.png" alt="Get Social" />' +
'<ul id="icons"><li><img class="tiny" src="fb.png" alt="Facebook" /></li>'+
'<li><img class="tiny" src="twit.png" alt="Twitter" /></li></ul></span>'+
'</div><div id="inner"><div id="innest"><div id="message">Get Social With Comfort Suites!</div>'+
'<div id="close"><a id="closeB" href="#">X</a></div><ul class="idTabs">'+
imgs +'</ul>'+content +'</div></div></div>');
});
内容变量如下所示:
var content = (
'<div class="contentArea visible" id="fb">FB Content Area</div>'+
'<div class="contentArea" id="twit"><script>makeTwitterWidget();</script></div>'+
'<div class="contentArea" id="youtube">Youtube Video</div>'+
'<div class="contentArea" id="yelp">Yelp reviews</div>'+
'<div class="contentArea" id="ta">Trip Advisor Advice</div>'+
'<div class="contentArea" id="li">The Linked In Page</div>'
);
var内容=(
“FB内容区”+
'makeTwitterWidget();'+
“Youtube视频”+
“Yelp评论”+
“旅行顾问建议”+
“链接页面”
);
您是否考虑过您是否考虑过有一个未记录的功能,允许您以要加载小部件的元素的id为目标。
我可以使用$.getScript和twitter提供的普通小部件代码来加载它
这是我使用的脚本,我希望这有帮助
$(document).ready(function(){
$.getScript('http://widgets.twimg.com/j/2/widget.js', function () {
new TWTR.Widget({
version: 2,
type: 'profile',
id : 'twitterBox',
rpp: 4,
interval: 30000,
width: 'auto',
height: 'auto',
theme: {
shell: {
background: 'transparent', //this is important
color: '#333'
},
tweets: {
background: 'transparent', //this is important
color: '#666',
links: '#d14836'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
behavior: 'all'
}
}).render().setUser('username').start();
});
});
$(文档).ready(函数(){
$.getScript('http://widgets.twimg.com/j/2/widget.js,函数(){
新TWTR.Widget({
版本:2,
键入:“配置文件”,
id:'twitterBox',
rpp:4,
间隔时间:30000,
宽度:“自动”,
高度:“自动”,
主题:{
外壳:{
背景:'透明',//这很重要
颜色:“#333”
},
推特:{
背景:'透明',//这很重要
颜色:'#666',
链接:“#d14836”
}
},
特点:{
滚动条:false,
循环:false,
生活:假,
行为:“全部”
}
}).render().setUser('username').start();
});
});
如果有人还在为此挣扎,twitter可能已经为你解决了这个问题,
我更改了代码,以便按照您建议的方式进行设置,现在只需输入推特提要。页面的其余部分在加载时闪烁,然后只有twitter提要加载。你知道为什么吗?现在我得到一个错误,makeTwitterWidget未定义。我知道这是个小问题,但我想不出来。你知道问题在哪里吗?嗯,我一直在业余时间研究。这是一把小提琴,我的方法很管用。问题是如何控制从何处调用构造函数。我倾向于建议使用其他东西来构建tweet,因为twitter自己的tweet非常关注嵌入用例,所以您将始终与之抗争。看一看,我试着让jtweetsanywhere工作,但我甚至不能让它在我的页面上工作。它插入了一些包装器元素,但实际上没有插入任何tweet。为什么您希望javascript包含侧栏?有没有什么特别的理由不使用纯html(这将减少负载并增加简单性)?这是我创建的一个插件,我只想添加到一堆不同的站点;简单的include(即在php:include('twitter_widget.php');)有什么不对?它更快、更简单,并且尽可能容易实现(它甚至可以保护一行代码;)
var makeTwitterWidget = function () {
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 6000,
width: 250,
height: 280,
theme: {
shell: {
background: '#333333',
color: '#ffffff'
},
tweets: {
background: '#ffffff',
color: '#444444',
links: '#e02046'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
}
})
.render()
.setUser('CSuitesIndepend')
.start();
});
}
var content = (
'<div class="contentArea visible" id="fb">FB Content Area</div>'+
'<div class="contentArea" id="twit"><script>makeTwitterWidget();</script></div>'+
'<div class="contentArea" id="youtube">Youtube Video</div>'+
'<div class="contentArea" id="yelp">Yelp reviews</div>'+
'<div class="contentArea" id="ta">Trip Advisor Advice</div>'+
'<div class="contentArea" id="li">The Linked In Page</div>'
);
$(document).ready(function(){
$.getScript('http://widgets.twimg.com/j/2/widget.js', function () {
new TWTR.Widget({
version: 2,
type: 'profile',
id : 'twitterBox',
rpp: 4,
interval: 30000,
width: 'auto',
height: 'auto',
theme: {
shell: {
background: 'transparent', //this is important
color: '#333'
},
tweets: {
background: 'transparent', //this is important
color: '#666',
links: '#d14836'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
behavior: 'all'
}
}).render().setUser('username').start();
});
});